leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

1738.cpp (696B)


      1 class Solution {
      2   public:
      3     int kthLargestValue(const vector<vector<int>> &matrix, int k) {
      4         static int crnt[1001], prev[1001];
      5         const int n = matrix.size(), m = matrix[0].size();
      6         priority_queue<int> pq;
      7 
      8         memset(prev, 0x00, sizeof(prev));
      9         for (int i = 0; i < n; i++) {
     10             memset(crnt, 0x00, sizeof(crnt));
     11             pq.push(crnt[0] = prev[0] ^ matrix[i][0]);
     12             for (int j = 1; j < m; j++) {
     13                 crnt[j] = matrix[i][j] ^ prev[j] ^ crnt[j - 1] ^ prev[j - 1];
     14                 pq.push(crnt[j]);
     15             }
     16             swap(prev, crnt);
     17         }
     18 
     19         while (--k)
     20             pq.pop();
     21         return pq.top();
     22     }
     23 };