id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
3,550 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 3 | {
"code": "#define ll long long\nclass Solution {\npublic:\n long long maximumValueSum(vector<vector<int>>& board) {\n int m = board.size(), n = board[0].size();\n multiset<vector<ll>>up,down;\n vector<vector<int>>preUp(m,vector<int>(n,0));\n vector<vector<int>>preDown(m,vector<int>(n,0... |
3,550 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 3 | {
"code": "#include <bits/stdc++.h>\nusing namespace std;\n#define fo(i, n) for (int i = 0; i < n; i++)\n#define Fo(i, a, n) for (int i = a; i < n; i++)\n#define ll long long\n#define deb(x) cout << #x << \"=\" << x << endl\n#define deb2(x, y) cout << #x << \"=\" << x << \",\" << #y << \"=\" << y << endl\n#define pb ... |
3,550 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 3 | {
"code": "class Solution {\n const int MAX = 100;\n const int64_t INF = (int64_t)2e18;\npublic:\n int64_t dfs(int n, std::vector<std::vector<int>>& a, std::vector<std::vector<int>>& c, int r, std::bitset<100> cs, std::vector<std::unordered_map<std::bitset<100>, int64_t>>& dp) {\n if(cs.count() == 3) ... |
3,550 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 3 | {
"code": "class Solution {\n \n // return {val, index} of the 3 largest elements\n vector<pair<int, int>> findTop3(vector<int> &v) {\n // \n // is this a min heap or a max heap?\n // min heap, because if a[i] > top of min_heap then we can simply replace top with a[i]\n // min hea... |
3,550 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 3 | {
"code": "class Solution {\npublic:\n \n long long helper(int row, bitset<100> mask, int rowCnt ,vector<vector<pair<int,int>>>& board,vector<vector<unordered_map<bitset<100>,long long>>> &dp){\n // base case\n if(row == board.size() && rowCnt != 0) return LLONG_MIN;\n if(rowCnt == 0 || row... |
3,550 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 3 | {
"code": "// #define int long long\nbool cmp(vector<int>& a, vector<int>& b){\n if(a[0] > b[0]){return true;}\n return false;\n }\n\nvector<vector<int>>bd;\nbool cmp1(vector<int>& a , vector<int>& b){\n // cout<<a[0]<<\" \"<<a[1]<<\" \"<<b[0]<<b[1]<<endl;\n if(bd[a[0]][a[1]] > bd[b[0]][b[1]]){... |
3,550 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 3 | {
"code": "class Solution {\npublic:\n long long maximumValueSum(vector<vector<int>>& v) {\n using ll = long long;\n int n = v.size() , m = v[0].size();\n vector<vector<int>> up(n , vector<int> (m , -2e9)) , down(n , vector<int> (m));\n for(int i = 0 ; i < n ; i++){\n for(int... |
3,550 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 3 | {
"code": "typedef long long ll;\nclass Solution {\npublic:\n vector<int> calcmaxm(vector<int> &v)\n {\n ll maxm1 = -1e10, maxm2 = -1e10, maxm3 = -1e10;\n int idx1 = -1, idx2 = -1, idx3 = -1;\n int n = v.size();\n for(int i=0;i<n;i++)\n {\n if(v[i] > maxm1)\n ... |
3,550 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 3 | {
"code": "typedef long long ll;\nclass Solution {\npublic:\n vector<int> calcmaxm(vector<int> &v)\n {\n ll maxm1 = -1e10, maxm2 = -1e10, maxm3 = -1e10;\n int idx1 = -1, idx2 = -1, idx3 = -1;\n int n = v.size();\n for(int i=0;i<n;i++)\n {\n if(v[i] > maxm1)\n ... |
3,550 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 3 | {
"code": "typedef long long ll;\nclass Solution {\npublic:\n vector<int> calcmaxm(vector<int> &v)\n {\n ll maxm1 = -1e10, maxm2 = -1e10, maxm3 = -1e10;\n int idx1 = -1, idx2 = -1, idx3 = -1;\n int n = v.size();\n for(int i=0;i<n;i++)\n {\n if(v[i] > maxm1)\n ... |
3,550 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 3 | {
"code": "typedef long long ll;\nclass Solution {\npublic:\n vector<int> calcmaxm(vector<int> &v)\n {\n ll maxm1 = -1e10, maxm2 = -1e10, maxm3 = -1e10;\n int idx1 = -1, idx2 = -1, idx3 = -1;\n int n = v.size();\n for(int i=0;i<n;i++)\n {\n if(v[i] > maxm1)\n ... |
3,550 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 3 | {
"code": "typedef long long ll;\nclass Solution {\npublic:\n vector<int> calcmaxm(vector<int> &v)\n {\n ll maxm1 = -1e10, maxm2 = -1e10, maxm3 = -1e10;\n int idx1 = -1, idx2 = -1, idx3 = -1;\n int n = v.size();\n for(int i=0;i<n;i++)\n {\n if(v[i] > maxm1)\n ... |
3,550 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 3 | {
"code": "class Solution {\npublic:\n#define PLL pair<long long, long long>\n long long maximum(long long& a, long long& b) {\n if (a >= b)\n return a;\n return b;\n }\n\n static bool cmp(pair<long long, PLL> &a, pair<long long, PLL> &b) {\n return a.first > b.first;\n }\n... |
3,550 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 3 | {
"code": "\nvector<int> solve(vector<int>& a){\n vector<pair<int,int>> v;\n for(int i=0;i<a.size();i++) v.push_back({a[i],i});\n sort(v.begin(),v.end());\n int ind=a.size();\n ind--;\n vector<int> ans;\n ans.push_back(v[ind].second);\n ans.push_back(v[ind-1].second);\n ans.push_back(v[ind-... |
3,550 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> combs;\n long long maximumValueSum(vector<vector<int>>& board) {\n int R = board.size(), C = board[0].size();\n long long res = LONG_LONG_MIN;\n // find three biggest number of every row\n vector<vector<int>> biggests; // ind... |
3,550 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 3 | {
"code": "class Solution {\npublic:\n static bool my_cmp(vector<long long> & vec_a, vector<long long> & vec_b){\n return vec_a[0] > vec_b[0];\n }\n long long takeAndIterate(vector<vector<long long> >& dp, vector<vector<long long> >& taken, int m, int n, int depth){\n long long max_score = -92... |
3,550 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 3 | {
"code": "class Solution {\npublic:\n using ll = long long;\nusing ull = unsigned long long;\nusing lld = long double;\nusing pii = pair<int, int>;\nusing pll = pair<ll, ll>;\nusing vi = vector<int>;\nusing vl = vector<ll>;\nusing vii = vector<pii>;\nusing vll = vector<pll>;\nusing vvi = vector<vi>;\nusing vs = v... |
3,550 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 3 | {
"code": "#define ll long long\nconst ll INF=1e18;\nclass Solution {\npublic:\n long long maximumValueSum(vector<vector<int>>& b) {\n int n=b.size();\n int m=b[0].size();\n vector<vector<ll>>colmax3els(m,vector<ll>(3,-INF));\n multiset<pair<int,int>,greater<pair<int,int>>>maxels;\n ... |
3,550 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 3 | {
"code": "class Solution {\npublic:\n long long maximumValueSum(vector<vector<int>>& board) {\n \n int n = board.size();\n int m = board[0].size();\n vector<vector<vector<int>>> c(n);\n for(int i = 0; i < n; i ++) \n c[i] = highest(board[i]);\n vector<vector<ve... |
3,550 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 3 | {
"code": "class Solution {\npublic:\n long long maximumValueSum(vector<vector<int>>& board) {\n int r = board.size(), c = board[0].size();\n vector<vector<vector<int>>> values(r);\n for(int i=0;i<r;i++){\n priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> p... |
3,550 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 3 | {
"code": "class Solution {\npublic:\n long long maximumValueSum(vector<vector<int>>& board) {\n int r = board.size(), c = board[0].size();\n vector<vector<vector<int>>> values(r);\n for(int i=0;i<r;i++){\n priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> p... |
3,550 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 3 | {
"code": "class Solution {\npublic:\n long long maximumValueSum(vector<vector<int>>& grid) {\n int i ; \n int j ; \n long long sm = -1e15;\n int k ; \n int col = grid[0].size();\n int row= grid.size();\n vector<vector<int > > dum(col);\n for(i=0;i<col; i++){... |
3,550 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 3 | {
"code": "class Solution {\npublic:\n long long maximumValueSum(vector<vector<int>>& board) {\n int m=board.size();\n int n=board[0].size();\n map<int,vector<int>>colmax;\n for(int i=0;i<n;i++){\n vector<pair<int,int>>col;\n for(int j=0;j<m;j++){\n ... |
3,550 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 3 | {
"code": "#define pb push_back\n#define all(x) x.begin(), x.end()\nclass Solution {\npublic:\n long long maximumValueSum(vector<vector<int>>& b) {\n int n= b.size(), m= b[0].size();\n vector<vector<int>> pos(n);\n for(int i=0; i<n;i++){\n vector<int> v(all(b[i]));\n sort... |
3,550 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 3 | {
"code": "#define ll long long\n\nclass Solution {\npublic:\n \n ll solve(vector<pair<int, int>> &a, vector<pair<int, int>> &b, vector<pair<int, int>> &c)\n {\n ll ans = -4e9;\n for (int i=0;i<3;i++)\n {\n for (int j=0;j<3;j++)\n {\n for (int k=0;k<3... |
3,550 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 3 | {
"code": "class Solution {\n #define ll long long\n\n \n \n ll func(int index, int a, int b, int count, vector<vector<int>>& v1,\n vector<vector<int>>& temp, vector<map<pair<int,int>, ll>>& dp ){\n if( count == 3) return 0;\n if( index == v1.size()) return -1e18-7;\n if( ... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 0 | {
"code": "class Solution {\npublic:\n long long maximumValueSum(vector<vector<int>>& board) \n {\n priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>, greater<>> minQ; // first = value, second = x-coordinate, third = y-coordinate\n priority_queue<tuple<int, int, int>> maxQ;\n ... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 0 | {
"code": "vector<vector<int>> grid;\n#define ll long long\nclass Solution {\npublic:\n vector<int> getMax(vector<int> &v,int n)\n {\n int max1=INT_MIN;\n int max2=INT_MIN;\n int max3=INT_MIN;\n int idx1=-1;\n int idx2=-1;\n int idx3=-1;\n for(int i=0;i<n;i++)\n ... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 0 | {
"code": "class Solution {\npublic:\n long long maximumValueSum(vector<vector<int>>& b) {\n long long ans=-3e10;\n\n int m=b.size(), n=b[0].size();\n vector<tuple<int,int,int>> vec;\n for(int i=0; i<m; i++)\n {\n priority_queue<tuple<int,int,int>> pq;\n for... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 0 | {
"code": "#pragma GCC optimize(\"O3\",\"unroll-loops\")\n#pragma GCC optimize(\"Ofast\")\nclass Solution {\npublic:\n long long maximumValueSum(vector<vector<int>>& board) {\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n int n = board.size(), m = board[0].size(); \n vecto... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 0 | {
"code": "class Solution {\npublic:\n long long maximumValueSum(vector<vector<int>>& board) {\n int n(board.size()), m(board[0].size());\n if (n > m) {\n swap(n, m);\n vector<vector<int>> grid(n, vector<int>(m));\n for (int i(0); i < n; ++i) for (int j(0); j < m; ++j... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 0 | {
"code": "#define ll long long\n#define ff first\n#define ss second\n#define pii pair<long long,long long>\nclass Solution {\npublic:\n \n void getMax(int i,vector<vector<int>>& v,vector<vector<pair<ll,ll>>>&mp){\n priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>pq;\n pq... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 0 | {
"code": "class Solution {\npublic:\n long long maximumValueSum(vector<vector<int>>& mat) {\n typedef long long LL;\n static const int maxn = 509;\n int r = mat.size(), c = mat[0].size();\n LL ans = LLONG_MIN;\n static int sz[maxn];\n static pair<int, int> row[maxn][3];\n... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 0 | {
"code": "class Solution {\npublic:\n struct dt { long long x; int y, z; };\n long long maximumValueSum(vector<vector<int>>& board) {\n //board = {{1,2,3},{4,5,6},{7,8,9}};\n //board = {{1,1,1},{1,1,1},{1,1,1}};\n //board = {{50,-58,37,62},{-46,79,-41,27},{-95,-17,58,47},{50,92,-11,18}};\n... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 1 | {
"code": "#define ll long long\nconst int N = 500, M = 500;\npair<int, int> maxi[N][M];\nint vis[N][M];\nclass Solution {\npublic:\n long long maximumValueSum(vector<vector<int>>& arr) {\n ll n = arr.size(), m = arr[0].size();\n\n for(int i = 0; i < n; i++){\n for(int j = 0; j < m; j++) c... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 1 | {
"code": "#define ll long long\nconst int N = 500, M = 500;\npair<int, int> maxi[N][M];\nint vis[N][M];\nclass Solution {\npublic:\n long long maximumValueSum(vector<vector<int>>& arr) {\n ll n = arr.size(), m = arr[0].size();\n\n for(int i = 0; i < n; i++){\n for(int j = 0; j < m; j++) c... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 1 | {
"code": "using ll = long long;\n\n#ifndef debug\n#define debug(...) 1\n#endif\n\nclass Solution {\npublic:\n long long solve1(vector<vector<int>>& board) {\n const int n = board.size();\n const int m = board.front().size();\n\n priority_queue<pair<int, pair<int, int>>, vector<pair<int, pair<int, int>>>, l... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 1 | {
"code": "class Solution {\npublic:\n long long maximumValueSum(vector<vector<int>>& board) {\n int m = board.size(); // row size\n int n = board[0].size(); // column size\n \n // Step 1: Collect top 3 maximum values for each row\n vector<vector<pair<int,int>>> max3(m);\n ... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 1 | {
"code": "class Solution {\npublic:\n long long maximumValueSum(vector<vector<int>>& a) {\n int n = a.size() , m = a[0].size() , posX , posY , k =0;\n long long ans= LONG_MIN, res = INT_MIN ; \n vector<int> colCount(m,0);\n vector<vector<int>> mxRow , topThree(3,{INT_MIN,-1,-1}) , topF... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 1 | {
"code": "typedef array<long long,2> ai;\nclass Solution {\npublic:\n int r = 9;\n ai best (vector<ai>& v, int a, int b = -1) {\n for (int i = 0; i < v.size(); i++) {\n if(v[i][1] != a && v[i][1] != b) {\n return {v[i][0],v[i][1]};\n }\n }\n long long i... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 1 | {
"code": "class Solution {\npublic:\n long long maximumValueSum(vector<vector<int>>& board) {\n int nRow = board.size();\n int nCol = board[0].size();\n vector<long long> maxSuf = vector<long long>();\n vector<vector<pair<int, int> > > b = vector<vector<pair<int, int> > >();\n \... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 1 | {
"code": "using ll = long long;\n\n#ifndef debug\n#define debug(...) 1\n#endif\n\nclass Solution {\npublic:\n long long solve1(vector<vector<int>>& board) {\n const int n = board.size();\n const int m = board.front().size();\n\n priority_queue<pair<int, pair<int, int>>, vector<pair<int, pair<int, int>>>, l... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 1 | {
"code": "class Solution {\npublic:\n\n long long dp[503][503];\n\n long long rec(int row, int p2, int p1, vector<vector<pair<long long, int>>> &vp){\n if(row >= vp.size())\n return (-1e18);\n\n if(dp[row][p1 + 1] != -1)\n return dp[row][p1 + 1];\n\n\n //not in the sa... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 1 | {
"code": "class Solution {\npublic:\n long long maximumValueSum(vector<vector<int>>& board) {\n int n = board.size(), m = board[0].size();\n vector<vector<pair<long long, int> > > mx(n, vector<pair<long long, int>>(3, {-1e15, 0}));\n for(int i=0;i<n;i++){\n for(int k=0;k<m;k++){\n ... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 1 | {
"code": "class Solution {\npublic:\n long long maximumValueSum(vector<vector<int>>& board) {\n int m = board.size();\n int n = board[0].size();\n int c = 0;\n // string s;\n // for(int i=0;i<n;i++){\n // s+='0';\n // }\n vector<vector<pair<int,int>>> tp... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 1 | {
"code": "class Solution {\npublic:\n long long maximumValueSum(vector<vector<int>>& bd) {\n //solve using prefix and suffix of each row\n int m=bd.size(),n=bd[0].size();\n vector<vector<int>> pref(m,vector<int>(n,0));\n vector<vector<int>> suff=pref,ld=pref,lt=pref,rd=pref,rt=pref,md=... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 2 | {
"code": "class Solution {\npublic:\n long long maximumValueSum(vector<vector<int>>& bbb) {\n \n int n=bbb.size();\n int m=bbb[0].size();\n vector<vector<long long int>> b(n,vector<long long int>(m));\n for(int i=0;i<n;i++)\n {\n for(int j=0;j<m;j++)\n ... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 2 | {
"code": "class Solution {\npublic:\n long long maximumValueSum(vector<vector<int>>& board) {\n const int m = board.size(), n = board[0].size();\n vector<array<int, 3> > top (m);\n for (int i = 0; i < m; ++i) {\n bool ff = false, sf = false, tf = false;\n int first, seco... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 2 | {
"code": "class Solution {\npublic:\n long long dp[502][502];\n long long helper(int row, int prev2, int prev1, vector<vector<pair<long long,int>>> &grid){\n if(row>=grid.size()) return -1e18;\n if(dp[row][prev1+1]!=-1) return dp[row][prev1+1];\n \n\t\t// not placing rook in the current ro... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 2 | {
"code": "#include<bits/stdc++.h>\nusing namespace std;\nusing ll=long long;\n\n\nclass Solution {\npublic:\n ll dp[502][502];\n\n ll genv(ll row,ll prev1,ll prev2,vector<vector<pair<ll,ll>>> &v)\n {\n if(row>=v.size())\n {\n return -1e15;\n }\n\n if(dp[row][prev1+1]!=... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 2 | {
"code": "static const int MN = 501;\nusing ll = long long;\nusing pll = pair<ll, ll>;\nconst ll LLINF = 0x3f3f3f3f3f3f3f3f, INF = 0x3f3f3f3f;\n#define fs first\n#define sn second\n\nvoid maxa(ll &a, ll b) {\n a = max(a, b);\n}\n\n#define neq(a, b, c) (((a) != (b)) && ((a) != (c)) && ((b) != (c)))\n\npll top3All[... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 2 | {
"code": "class Solution {\n static const int MN = 501;\n using ll = long long;\n using pll = pair<ll, ll>;\n const ll LLINF = 0x3f3f3f3f3f3f3f3f, INF = 0x3f3f3f3f;\n #define fs first\n #define sn second\n \n void maxa(ll &a, ll b) {\n a = max(a, b);\n }\n \n pll top3All[MN][3... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 2 | {
"code": "class Solution {\npublic:\n typedef long long ll; \n long long maximumValueSum(vector<vector<int>>& board) {\n ll n=board.size();\n ll m=board[0].size();\n vector<pair<ll,pair<ll,ll>>> values;\n for(ll i=0;i<n;i++){\n vector<pair<ll,ll>> temp;\n for(l... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 2 | {
"code": "class Solution {\npublic:\n long long solve(int i,vector<vector<pair<long long,long long>>>&best,int c1,int c2)\n {\n if(i>=best.size())\n return -1e18;\n long long curr=solve(i+1,best,c1,c2);\n for(int j=0;j<3;j++)\n {\n if(best[i][j].second!=c1 && be... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 2 | {
"code": "bool notagain = false;\nint logs[501];\nint sparse[500][500][9][9]; \nint top_three[500][3];\n\nvoid pre() {\n if (notagain) return;\n notagain = true;\n logs[1] = 0;\n for (int i = 2; i <= 500; i++) {\n logs[i] = logs[i / 2] + 1;\n }\n}\n\ntemplate <typename T, typename F>\nclass Sp... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 2 | {
"code": "class Solution {\npublic:\n #define ll long long\n int m;\n int n;\n\n // TC : O((M*3)^2 * K) Where K is the average time of finding elements from the store array\n // SC : O(M * 3)\n ll way_1(vector<vector<int>>& board) {\n vector<vector<pair<int, int>>> newBoard(m, vector<pair<in... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 2 | {
"code": "class Solution {\npublic:\n long long f(vector<vector<pair<int,int>>> &v, \n int i, int j, int j1, int m, vector<vector<long long>> &dp)\n {\n int n=v.size();\n \n if(i>=n) return -1e12;\n\n if(dp[i][j]!=-1) return dp[i][j];\n\n long long ans=f(v,i+1,j,j1,m,dp);\... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 2 | {
"code": "class Solution {\npublic:\n long long maximumValueSum(vector<vector<int>>& board) {\n long long ans_1 = 0;\n long long ans_2 = 0;\n long long ans_3 = 0;\n long long ans_4 = 0;\n long long ans_5 = 0;\n long long ans_6 = 0;\n long long ans_7 = 0;\n l... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 2 | {
"code": "class Solution {\npublic:\ntypedef long long int ll;\n long long maximumValueSum(vector<vector<int>>& board) {\n vector<pair<ll,pair<ll,ll> > >v;\n for(ll i = 0;i<board.size();i++){\n for(ll j = 0;j<board[0].size();j++){\n v.push_back({board[i][j],{i,j}});\n ... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 2 | {
"code": "using i64 = long long;\n\nconstexpr i64 inf = 1e18;\n\nclass Solution {\npublic:\n long long maximumValueSum(vector<vector<int>>& board) {\n int m = board.size(), n = board[0].size();\n std::vector c1(m, std::vector<int>(n));\n std::vector c2(m, std::vector<int>(n));\n for (i... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 2 | {
"code": "#define all(x) x.begin(), x.end()\nusing ull = unsigned long long;\nusing ll = long long;\n\nbool fIO() {\n ios::sync_with_stdio(false);\n ios_base::sync_with_stdio(false);\n ios::sync_with_stdio(false);\n cout.tie(nullptr);\n cin.tie(nullptr);\n return true;\n}\nbool y4555123 = fIO();\nc... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 2 | {
"code": "#define all(x) x.begin(), x.end()\nusing ull = unsigned long long;\nusing ll = long long;\n\nbool fIO() {\n ios::sync_with_stdio(false);\n ios_base::sync_with_stdio(false);\n ios::sync_with_stdio(false);\n cout.tie(nullptr);\n cin.tie(nullptr);\n return true;\n}\nbool y4555123 = fIO();\nc... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 2 | {
"code": "//#define int long long \n#define pii pair<int, int>\n#define ff first\n#define ss second\n//#define int long long \n#define all(v) v.begin(), v.end()\n#define pb push_back\n\nclass Solution {\npublic: \n\n long long maximumValueSum(vector<vector<int>>& board) {\n \n map<int, bool>RowOk[50... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 2 | {
"code": "class Solution {\npublic:\n long long maximumValueSum(vector<vector<int>>& board) {\n int m = board.size();\n int n = board[0].size();\n vector<vector<int>> upper = board, lower = board;\n for (int i = 1;i<m;i++) {\n for (int j=0;j<n;j++) {\n upper[i... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 2 | {
"code": "#define ll long long\n#define pii pair<int, int>\n#define fi first\n#define se second\nclass Solution {\npublic:\n long long maximumValueSum(vector<vector<int>>& board) {\n int n = board.size();\n int m = board[0].size();\n auto cmp = [&](pair<ll, pii> a, pair<ll, pii> b){\n ... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 2 | {
"code": "class Solution {\npublic:\n long long maximumValueSum(const std::vector<std::vector<int>>& board) {\n const size_t R = board.size();\n const size_t C = board.front().size();\n\n long long ans = std::numeric_limits<long long>::min();\n \n {\n std::vector<std:... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 2 | {
"code": "#define lli long long int \n#define ld long double\n#define vi vector<int>\n#define vlli vector<lli>\n#define vpii vector<pair<int, int>>\n#define pb push_back\n#define all(__x) __x.begin(),__x.end()\n\ntemplate<typename T> void debug(T _a) {cout << _a << \" \";}\ntemplate<typename T1, typename T2> void de... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 2 | {
"code": "class Solution {\npublic:\n long long maximumValueSum(vector<vector<int>>& a) {\n int n = a.size() , m = a[0].size() , posX , posY , k =0;\n long long ans= LONG_MIN, res = INT_MIN ; \n vector<int> colCount(m,0);\n vector<vector<int>> mxRow, topFour(4);\n priority_queue... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 2 | {
"code": "class Solution {\npublic:\n // long long memo[502][502];\n std::vector<std::vector<long long>> memo;\n\n // Assumes that prev1 is reserved for second largest column\n long long dp(int row, int prev1, int prev2, std::vector<std::vector<std::pair<int, long long>>> &grid) {\n if (row >= grid.size()) {\... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 2 | {
"code": "class Solution {\npublic:\n typedef long long ll;\n ll dp[8][501][501];\n ll solve(vector<vector<pair<ll,ll>>>& nums,int ind,int c1,int c2){\n int n=nums.size();\n if(ind==n) return -1e18;\n if(ind>=8) return -1e18;\n\n if(dp[ind][c1+1][c2+1]!=-1) return dp[ind][c... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 2 | {
"code": "using ll = long long;\n\nclass SegmentTree {\npublic:\n SegmentTree(ll n) : n(n), MIN_VAL(-1e9) {\n tree.resize(4 * n, MIN_VAL);\n }\n\n void update(ll node, ll left, ll right, ll index, ll value) {\n if (index < left || index > right) {\n return;\n }\n\n if ... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 2 | {
"code": "using ll = long long;\n\nclass SegmentTree {\npublic:\n SegmentTree(ll n) : n(n), MIN_VAL(-1e9) {\n tree.resize(4 * n, MIN_VAL);\n }\n\n void update(ll node, ll left, ll right, ll index, ll value) {\n if (index < left || index > right) {\n return;\n }\n\n if ... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 2 | {
"code": "#include <bits/stdc++.h>\nusing namespace std;\ntypedef long long ll;\ntypedef vector<int> vi;\ntypedef pair<int,int> pii;\ntypedef pair<double, double> pdd;\n#define pb push_back\n#define mp make_pair\n#define fs first\n#define sc second\n#define rep(i, from, to) for (int i = from; i < (to); ++i)\n#define... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 2 | {
"code": "#include <bits/stdc++.h>\n#pragma GCC optimize(\"Ofast\", \"unroll-loops\")\nusing namespace std;\ntypedef long long ll;\ntypedef vector<int> vi;\ntypedef pair<int,int> pii;\ntypedef pair<double, double> pdd;\n#define pb push_back\n#define mp make_pair\n#define fs first\n#define sc second\n#define rep(i, f... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 2 | {
"code": "class Solution {\npublic:\n long long maximumValueSum(vector<vector<int>>& arr) {\n int n=arr.size();\n int m=arr[0].size();\n vector<vector<pair<int,int>>> top3(n);\n vector<pair<int,pair<int,int>>> all;\n\n for(int i=0;i<n;i++){\n for(int j=0;j<m;j++){\n ... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 2 | {
"code": "class Solution {\npublic:\n long long maximumValueSum(vector<vector<int>>& board) {\n int maxRow = static_cast<int>(board.size());\n int maxCol = static_cast<int>(board[0].size());\n auto comp = [](const std::vector<int> &a, const std::vector<int> &b) {\n return a[0] < b[... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 2 | {
"code": "#pragma GCC optimize(\"O3,unroll-loops\")\n#pragma GCC target(\"avx2,bmi2,lzcnt,popcnt\")\nclass Solution {\npublic:\n long long maximumValueSum(vector<vector<int>>& b) {\n long long ans=LLONG_MIN;\n int n=b.size(), m=b[0].size();\n vector<vector<int>> v, arr;\n for(int i=0; ... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 2 | {
"code": "#pragma GCC optimize(\"O3,unroll-loops\")\n#pragma GCC target(\"avx2,bmi2,lzcnt,popcnt\")\nclass Solution {\npublic:\n long long maximumValueSum(vector<vector<int>>& b) {\n long long ans=LLONG_MIN;\n int n=b.size(), m=b[0].size();\n vector<vector<int>> v, arr;\n for(int i=0; ... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 2 | {
"code": "#include<bits/stdc++.h>\nusing namespace std;\n\nclass Solution {\npublic:\n long long returnMaxi(vector<pair<long long, pair<int,int>>>& b){\n int len = b.size();\n long long maxi = LLONG_MIN;\n \n for(int i=0;i<len-2;i++){\n for(int j=i+1;j<len-1;j++){\n ... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 2 | {
"code": "class Solution {\npublic:\n long long inf = 1e15 + 1;\n long long Helper(vector<int> a, vector<int> b, vector<int> c){\n //cout<<\"a: \"; printArr(a);\n //cout<<\"b: \"; printArr(b);\n //cout<<\"c: \"; printArr(c);\n vector<int> aL = a, aR = a;\n vector<int> cL = c,... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 2 | {
"code": "class Solution {\n public:\n\tlong long maximumValueSum(vector<vector<int>>& a) {\n\t\tint n = a.size(), m = a.front().size();\n\n\t\tvector<tuple<int, int, int>> candidates;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tfor (int j = 0; j < m; ++j) {\n\t\t\t\tcandidates.push_back({a[i][j], i, j});\n\t\t\t}\n\t... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 2 | {
"code": "#define ll long long\nclass Solution {\npublic:\n long long maximumValueSum(vector<vector<int>>& board) {\n ll n = board.size();\n ll m = board[0].size();\n vector<vector<pair<ll,ll>>>pqs(n);\n for (ll i = 0; i<n; i++){\n for (ll j = 0; j<m; j++){\n ... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 3 | {
"code": "class Solution {\npublic:\n long long maximumValueSum(vector<vector<int>>& v) {\n int n=v.size(),m=v[0].size();\n vector<vector<int>>dp(n,vector<int>(m,-2e9));\n vector<vector<int>>dp2(n,vector<int>(m,-2e9));\n for(int i=0;i<n;i++){\n for(int j=0;j<m;j++){\n ... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 3 | {
"code": "#define ll long long\nclass Solution {\npublic:\n long long maximumValueSum(vector<vector<int>>& board) {\n ll n = board.size();\n ll m = board[0].size();\n vector<vector<pair<ll, ll>>> v(n, vector<pair<ll, ll>>(3));\n for (ll i = 0; i < n; i++) {\n priority_queue<... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 3 | {
"code": "bool comp(vector<int>&a, vector<int>&b){\n return a[0]>b[0];\n }\nclass Solution {\npublic:\n long long solve(vector<vector<long long>>& grid) {\n \n long long n = grid.size();\n long long m = grid[0].size();\n vector<vector<long long>> tr, tl;\n tr = grid;\n ... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 3 | {
"code": "class Solution {\npublic:\n #define ll long long int\n long long maximumValueSum(vector<vector<int>>& board) {\n int m = board.size();\n int n = board[0].size();\n ll res = -1e10;\n vector<vector<pair<ll, int>>> cells(m, vector<pair<ll, int>>());\n vector<pair<ll, p... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 3 | {
"code": "class Solution {\npublic:\n static bool compare(vector<long long> v1,vector<long long> v2)\n {\n return v1[0] > v2[0];\n }\n long long maximumValueSum(vector<vector<int>>& board) {\n int r = board.size(),c = board[0].size();\n vector< vector<long long> > allPoss;\n l... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 3 | {
"code": "class Solution {\npublic:\n static bool compare(vector<long long> v1,vector<long long> v2)\n {\n return v1[0] > v2[0];\n }\n long long maximumValueSum(vector<vector<int>>& board) {\n int r = board.size(),c = board[0].size();\n vector< vector<long long> > allPoss;\n l... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 3 | {
"code": "class Solution {\npublic:\n using LL = long long;\n\n LL maximumValueSum(vector<vector<int>>& board) {\n m = board.size();\n n = board[0].size();\n b = std::move(board);\n dp.assign(m, vector<array<LL, LEN>>(n));\n\n for (int i = 0; i < m; ++i) {\n for (i... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 3 | {
"code": "class Solution {\npublic:\n long long maximumValueSum(vector<vector<int>>& board) {\n int n(board.size()), m(board[0].size());\n //cout << n << \" x \" << m << \"\\n\";\n auto cmp = [&](auto& p, auto& q) {\n return board[p.first][p.second] > board[q.first][q.second];\n ... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 3 | {
"code": "#define INF 1e15\n#define min(a, b) ((a) < (b)? (a) : (b))\ntypedef long long ll;\nclass Solution {\nprivate:\n void solve(\n const vector<vector<int>> &positions,\n set<int> &row, set<int> &col, int n, int start,\n ll sum, ll &maxsum, int &end) {\n if (!n) {\n ... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 3 | {
"code": "#define pb push_back\n#define x first\n#define y second\n#define pdd pair<double,double>\n#define pii pair<int,int>\n#define pll pair<LL,LL>\n#define mp make_pair\n#define LL long long\n#define ULL unsigned long long\n#define sqr(x) ((x)*(x))\n#define pi acos(-1)\n#define MEM(x) memset(x,0,sizeof(x))\n#def... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 3 | {
"code": "class Solution {\n\n vector<vector<long long int>> maximumValueSum2BottomRight(vector<vector<int>>& board) {\n int m=board.size();\n int n=board[0].size();\n vector<vector<long long int>> DP(m,vector<long long int> (n,-1e15));\n vector<vector<long long int>> Right_max(m,vecto... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 3 | {
"code": "class Solution {\n\n vector<vector<long long int>> maximumValueSum2BottomRight(vector<vector<int>>& board) {\n int m=board.size();\n int n=board[0].size();\n vector<vector<long long int>> DP(m,vector<long long int> (n,-1e15));\n vector<vector<long long int>> Right_max(m,vecto... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 3 | {
"code": "class Solution {\npublic:\n set<int> r,c;\n\n bool compatible(pair<int,int> &p1, pair<int,int> &p2, pair<int,int> &p3){\n r.clear(),c.clear();\n r.insert(p1.first);\n c.insert(p1.second);\n r.insert(p2.first);\n c.insert(p2.second);\n r.insert(p3.first);\n ... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 3 | {
"code": "#define ll long long\nconst ll INF=1e18;\nclass Solution {\npublic:\n ll ans,n,m;\n void fliphorz(vector<vector<int>>&b){\n for(int i=0;i<n/2;i++)for(int j=0;j<m;j++)swap(b[i][j],b[n-1-i][j]);\n }\n void flipvert(vector<vector<int>>&b){\n for(int i=0;i<n;i++)for(int j=0;j<m/2;j++)... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 3 | {
"code": "class Solution {\npublic:\n bool doesNotMatch(vector<long long>& a, vector<long long>& b){\n return (a[1]!=b[1])&&(a[2]!=b[2]);\n }\n long long maximumValueSum(vector<vector<int>>& board) {\n vector<vector<long long>>v;\n for(int i=0; i<board.size(); i++){\n vector<... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 3 | {
"code": "class Solution {\npublic:\n static bool comp(vector<long long>&v1, vector<long long>&v2) {\n return v1[0] > v2[0];\n }\n long long maximumValueSum(vector<vector<int>>& board) {\n long long int ans = -1e17;\n int m = board.size(), n = board[0].size();\n vector<vector<lon... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 3 | {
"code": "class Solution {\npublic:\n bool doesNotMatch(vector<long long>& a, vector<long long>& b){\n return (a[1]!=b[1])&&(a[2]!=b[2]);\n }\n long long maximumValueSum(vector<vector<int>>& board) {\n vector<vector<long long>>v;\n for(int i=0; i<board.size(); i++){\n vector<... |
3,542 | <p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>
<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em>... | 3 | {
"code": "class Solution {\npublic:\n bool doesNotMatch(vector<long long>& a, vector<long long>& b){\n return (a[1]!=b[1])&&(a[2]!=b[2]);\n }\n long long maximumValueSum(vector<vector<int>>& board) {\n vector<vector<long long>>v;\n for(int i=0; i<board.size(); i++){\n vector<... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.