id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
3,523
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\npublic:\n vector<int> seg;\n void buildTree(int nodeInd,int l,int r,vector<int> &nums){\n if(l==r){\n seg[nodeInd] = nums[l];\n return;\n }\n\n int mid = l + (r-l)/2;\n buildTree(nodeInd*2+1,l,mid,nums);\n buildTree(nodeInd*2+...
3,523
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n if(k==1) return nums;\n vector<int> ans;\n unordered_set<int> s;\n int conse=0;\n int prev=nums[0];\n for(int i=1;i<k&&i<nums.size();i++){\n if(prev+1!=nums[i]){\n ...
3,523
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\npublic:\n // int check(vector<int>& nums,int l,int r){\n // int maxc = nums[l];\n // for(int i=l+1;i<=r;i++){\n // maxc = max(maxc,nums[i]);\n // if(nums[i]-nums[i-1] != 1) return -1;\n // }\n // return maxc;\n // }\n vector<int> ...
3,523
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n int n = nums.size();\n vector<int> ans;\n priority_queue<pair<int,int>> q;\n int l = 0, r = 0;\n int f = 0;\n while (r < n) {\n q.push({r,nums[r]});\n if(r>0...
3,523
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n vector<int> ans;\n vector<pair<int,int>> sorted;\n sorted.push_back({1, nums[0]});\n\n for(int i = 1; i < nums.size(); ++i) {\n if(nums[i] > nums[i - 1] && nums[i] - nums[i - 1] == 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>...
0
{ "code": "class Solution {\n private:\n using value_col_t = array<int, 2>;\n using max_3_stats_t = array<value_col_t, 3>;\n\n public:\n long long maximumValueSum(const vector<vector<int>> &board) {\n const int rows = static_cast<int>(board.size());\n const int cols = static_cast<int>(board.front().size());\...
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>...
0
{ "code": "/**\n * Time Complexity: O(rows * cols)\n * Space Complexity: O(rows)\n * where `rows` is the number of the rows of the 2D array `board`\n * `cols` is the number of the columns of the 2D array `board`\n */\nclass Solution {\n private:\n using value_col_t = array<int, 2>;\n using max_3_stats_t = arr...
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>...
0
{ "code": "class Solution {\n long long solve(vector<vector<pair<int,int>>> &maxi, int &r, vector<bool> &visCol, int rooks, int curRow){\n if(rooks==0){\n return 0;\n }\n if(curRow==r){\n return -3e9;\n }\n long long ans = solve(maxi,r,visCol,rooks,curRow+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>...
0
{ "code": "class Solution {\npublic:\n long long maximumValueSum(vector<vector<int>>& board) {\n int m = board.size(), n = board[0].size();\n vector<vector<pair<long long,int>>> top3(m, vector<pair<long long,int>>(3, make_pair(-20000000000ll, -1)));\n \n for (int i = 0; i < m; i++) {\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>...
0
{ "code": "class Solution {\npublic:\n long long maximumValueSum(vector<vector<int>>& board) {\n int m = board.size();\n int n = board[0].size();\n\n vector<vector<pair<long long, int>>> reducedBoard(m, vector<pair<long long, int>>(n));\n for (int i = 0; i < m; ++i) {\n for (...
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>...
0
{ "code": "class Solution {\npublic:\n long long maximumValueSum(vector<vector<int>>& nums) {\n vector<vector<pair<long long,int>>> lol(nums.size(),vector<pair<long long,int>>(3,{LLONG_MIN,INT_MIN}));\n long long maxi=LLONG_MIN;\n\n for(int i=0; i<nums.size(); i++){\n vector<pair<in...
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>...
1
{ "code": "class Solution {\nprivate:\n int m;\n int n;\n typedef long long ll;\n\n // TC : O((M*N)^3)\n ll brute(vector<vector<int>>& board) {\n ll ans = LLONG_MIN;\n\n // for Rook - I\n for (int a = 0; a < m; a ++) {\n for (int b = 0; b < n; b ++) {\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>...
1
{ "code": "class Solution {\nprivate:\n int m;\n int n;\n typedef long long ll;\n\n // TC : O((M*N)^3)\n ll brute(vector<vector<int>>& board) {\n ll ans = LLONG_MIN;\n\n // for Rook - I\n for (int a = 0; a < m; a ++) {\n for (int b = 0; b < n; b ++) {\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>...
2
{ "code": "class Solution {\npublic:\n long long dp[100][101][101];\n long long MIN = -(1e12);\n long long getans(int ind,int ind1,int ind2,vector<vector<pair<int,int>>> &vec) {\n\n if(ind >= vec.size())\n return (INT_MIN*1000ll);\n\n if(dp[ind][ind1+1][ind2+1] != -1)\n re...
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>...
2
{ "code": "class Solution {\n using ll = long long; \npublic:\n long long maximumValueSum(vector<vector<int>>& board) \n {\n int n = board.size();\n int m = board[0].size();\n \n vector<vector<pair<int, int>>> v(n);\n for(int i = 0; i < n; i++)\n {\n se...
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>...
2
{ "code": "class Solution {\npublic:\n long long rec(vector<vector<pair<long long,long long>>>&v,int c1,int c2,int i){\n if(i==v.size()){\n return -1e18;\n }\n long long s=LLONG_MIN;\n s=max(s,rec(v,c1,c2,i+1));\n if(c1==-1){\n s=max(s,v[i][0].first+rec(v,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>...
2
{ "code": "class Solution {\npublic:\n long long cal(vector<vector<pair<int, int> > >& arr, int row1, int row2, int row3) {\n long long ans = INT_MIN * 3LL;\n for(int i = 0; i < 3; i++) {\n for(int j = 0; j < 3; j++) {\n for(int k = 0; k < 3; k++) {\n 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>...
2
{ "code": "class Solution {\npublic:\n long long maximumValueSum(vector<vector<int>>& b) {\n auto comp = [](vector<int> &a, vector<int> &b){\n return a[0] < b[0];\n };\n // priority_queue<pair<int,vector<int>>> pq;\n // priority_queue<pair<int, vector<int>>, vector<pair<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>...
2
{ "code": "class Solution {\npublic:\n // We only need to store the results of the current row and the previous row\n vector<vector<long long>> dp_prev;\n vector<vector<long long>> dp_curr;\n\n long long maxi(long long i, long long firstj, long long secondj, vector<vector<pair<long long, long long>>>& arr...
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>...
2
{ "code": "class Solution {\npublic:\n long long maximumValueSum(vector<vector<int>>& board) {\n vector<vector<int>> marker(board.size(), vector<int>(board[0].size(), 0));\n priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>> pq;\n for(int row = 0; row < board.size(); 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>...
2
{ "code": "class Solution {\n int r1=-1,r2=-1,c1=-1,c2=-1; \n long long fun(vector<vector<int>>&v,int i,int cnt,int m){\n if(cnt==3)\n return 0;\n if(i>=v.size())\n return -(1e8*1e8*1ll);\n long long ans=-(1e9*1e9*1ll);\n for(int ind=i;ind<i+3;ind++)\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>...
2
{ "code": "class Solution {\npublic:\n long long dp[105][105][105];\n long long maxValue(int i, int firstj, int secondj, vector<vector<pair<long long,long long>>>&arr){\n if(i==arr.size())return -1e11;\n if(dp[i][firstj+1][secondj+1]!=-1){\n return dp[i][firstj+1][secondj+1];\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>...
2
{ "code": "class Solution {\npublic:\n long long dp[105][105][105];\n long long maxValue(int i, int firstj, int secondj, vector<vector<pair<long long,long long>>>&arr){\n if(i==arr.size())return -1e11;\n if(dp[i][firstj+1][secondj+1]!=-1){\n return dp[i][firstj+1][secondj+1];\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>...
2
{ "code": "class Solution {\nprivate:\n typedef long long int ll;\n ll ans = LLONG_MIN;\npublic:\n long long maximumValueSum(vector<vector<int>>& board) {\n ll n = board.size(),m = board[0].size();\n vector<vector<ll>> temp,arr;\n for(int i=0;i<n;i++)\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>...
2
{ "code": "class Solution {\npublic:\n typedef long long ll;\n ll dp[101][102][102];\n unordered_map<ll ,vector<vector<ll>>> mp;\n int m;\n ll Find(int idx ,int p1 ,int p2 ,vector<vector<int>>& board ,int count)\n {\n if(count==3) return 0;\n if(idx == board.size()) return -1e18;\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": "class Solution {\npublic:\n \n int n, m;\n \n long long dp[105][105][105][3];\n \n long long memo(int i, int j1, int j2,int cnt, vector<vector<int>> &board, vector<vector<pair<int,int>>> &g){\n \n if(cnt){\n return 0;\n }\n if(i== 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": "class Solution {\n long long solve(int n,vector<pair<int,pair<int,int>>> &v,set<int>&st,set<int>&st2,int k){\n if(k==3)return 0;\n if(n<0) return -1e15;\n long long ans=solve(n-1,v,st,st2,k);\n if(st.find(v[n].second.first)==st.end() && st2.find(v[n].second.second)==st2.end()...
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 dp[101][102][102][3];\n long long find(vector<vector<pair<int,int>>>&nums,int index,int col1,int col2,int k){\n if(index>=nums.size()||k>=3){\n return k==3?0:-1e18;\n }\n if(dp[index][col1+1][col2+1][k]!=-1) return dp[index][col1+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 #define ll long long\n\n ll dp[101][102][102][3];\n\n ll find(vector<vector<pair<int, int>>>&nums, int row, int col1, int col2, int k){\n if (k==3) return 0;\n if (row==nums.size()) return -1e18;\n\n if (dp[row][col1+1][col2+1][k]!=-1) return dp[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": "using i64 = long long;\n\n// atcoder library のものを改変\nnamespace internal {\ntemplate <class E>\nstruct csr {\n vector<int> start;\n vector<E> elist;\n explicit csr(int n, const vector<pair<int, E>>& edges)\n : start(n + 1), elist(edges.size()) {\n for (auto e: edges) { start[e.first + 1]++; }\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 ll long long \n int n, m;\n ll dp[101][101][101][4];\n\n ll f(int idx, int prv1, int prv2, int k, vector<vector<pair<int,int>>>& vals) {\n if (idx == n) {\n return (k == 0) ? 0 : LLONG_MIN;\n }\n if (k == 0) return 0;\n if...
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;\n\nclass Solution {\npublic:\n vector<ll> prefixMax(const vector<ll>& a, int n) {\n vector<ll> res(n);\n res[0] = a[0];\n for (int i = 1; i < n; ++i) res[i] = max( res[i-1], a[i] );\n return res;\n }\n \n vector<ll> suffixMax(const vector<ll>& a, int n) {\n vector<l...
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": "using ll = long long;\n\nclass Solution {\npublic:\n struct Edge {\n ll from, to, capacity, cost;\n };\n\n vector<vector<ll>> adj, cost, capacity;\n\n const ll INF = 1e18;\n\n void shortest_paths(ll n, ll v0, vector<ll>& d, vector<ll>& p) {\n d.assign(n, INF);\n d[v0] = ...
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 <vector>\n#include <set>\n#include <algorithm>\n#include <iostream>\n#include <climits>\n\nusing namespace std;\n\nclass Solution {\npublic:\n long long maximumValueSum(vector<vector<int>>& board) {\n int M = board.size();\n int N = board[0].size();\n long long INF = LLONG_...
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 bool check(long long row,long long col,vector<vector<long long>>& a){\n for(long long i=0;i<=col;i++){\n if(a[row][i] >= 1){\n return true;\n }\n }\n for(long long i=0;i<=row;i++){\n if(a[i][col] >= 1){\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 dp[101][101][101][4];\n int check[101][101][101][4];\n long long max(long long a, long long b){\n return a>b?a:b;\n }\n \n long long solve(vector<vector<int>> &board, vector<vector<int>> &row_max, int i, int rooks, int prev1, int prev2){\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 int n = board.size();\n int m = board[0].size();\n\n long long ans = LLONG_MIN;\n\n vector<vector<int>> v(n, vector<int>(3, INT_MIN));\n vector<int> temp (m);\n for(int i = 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 \n#define ll long long\n#define ld double\n#define pb push_back\n#define mp make_pair\n#define ff first\n#define se second\n#define endl '\\n'\n#define MAX 20...
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 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,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;\ntypedef unsigned long long ull;\ntypedef long double ld;\ntypedef pair<int, int> pii;\ntypedef pair<ll, ll> pll;\ntypedef pair<string, string> pss;\ntypedef vector<int> vi;\ntypedef vector<vi> vvi;\ntypedef vector<pii> vii;\ntypedef vector<pll> vll;\ntypedef vector<ll> vl;\ntypedef 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": "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<pair<int,int>>> top3;\n for(int i=0; i<n; i++)\n {\n // value, col\n vector<pair<int,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": "class Solution {\n public:\n long long maximumValueSum(vector<vector<int>>& board) {\n const int m = board.size(), n = board[0].size();\n vector<vector<tuple<int64_t, int, int>>> row_top3(m), col_top3(n);\n for (int i = 0; i < m; ++i) {\n vector<tuple<int64_t, int, int>> row_vals;\n for...
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;\ntypedef long long ll;\n\n#define sz(a, n) n = a.size()\n#define pb(a, x) a.push_back(x)\n#define loopz(n) for (int i = 0; i < n; i++)\n#define loopo(n) for (int i = 1; i <= n; i++)\n#define outo(x) cout << x << endl\n#define outt(x, y) cout << x << \" \" << y...
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 long long maxSum = -3e9;\n vector<vector<pair<int, int>>>\n vals(m, vector<pair<int, int>>(3, {-1e9, -1}));\n for (int 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 n=board.size();\n int m=board[0].size();\n set<pair<int,pair<int,int>>>st;\n vector<vector<pair<int,pair<int,int>>>>v(n,vector<pair<int,pair<int,int>>>(m));\n for(int i=0;i<n;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:\ntypedef long long ll;\n long long maximumValueSum(vector<vector<int>>& board) {\n ll i,j,k,val,x,y,n=(ll)board.size(),m=(ll)board[0].size(),md=1000000007,ans;\n vector<vector<ll>> v,v2,v3;\n \n ans=-3*md;\n \n for(i=0;i<n;i++){\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 vector<vector<int>> prefix_top_left;\n vector<vector<int>> prefix_top_right;\n vector<vector<int>> prefix_bottom_left;\n vector<vector<int>> prefix_bottom_right;\n vector<vector<int>> prefix_max;\n vector<vector<int>> suffix_max;\n\n vector<vector<int>> get_...
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 solve(int a,int b,int c,vector<vector<pair<int,int>>>&v2){\n vector<int>v(2);\n long long m=LLONG_MIN;\n long long curr=0;\n for(int i=0;i<3;i++){\n pair<int,int>p1=v2[a][i];\n v[0]=p1.second;\n curr=p1.fi...
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/*\nTake top3 elements in each row, 3n elements.\nTake top3 elements in each col, 3m elements.\nTake the intersection s of top3 in rows and top3 in cols.\nThen take top 11 elements of s.\nBrute force the combinations of 3 and check the condition,\nreturn the biggest result.\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": "class Solution {\npublic:\n\n long long solve(vector<vector<pair<long long, long long>>>& v) {\n sort(v.begin(),v.end());\n int n = v.size();\n long long ans = LONG_MIN;\n\n for (int i1 = 0; i1 < n - 2; ++i1) {\n for (int x1 = 0; x1 < 3; ++x1) {\n lo...
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 pi pair<int, int>\n#define pii pair<int, pi>\n#define f first\n#define s second\n\nconst int k = 3;\n\nclass Solution {\nprivate:\n void add(vector<pii> &pos, vector<pii> v){\n partial_sort(v.begin(), v.begin() + k, v.end(), greater<pii>());\n pos.insert(pos.end(), v.begin(), v.beg...
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 solve(vector<vector<pair<long long, long long>>>& v) {\n sort(v.begin(),v.end());\n int n = v.size();\n long long ans = LONG_MIN;\n\n for (int i1 = 0; i1 < n - 2; ++i1) {\n for (int x1 = 0; x1 < 3; ++x1) {\n lo...
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 const long long INF = 1e17;\n const long long inf = 1e9+7;\n long long maximumValueSum(vector<vector<int>>& v) {\n using ll = long long;\n int n = v.size(), m = v[0].size();\n ll ans = -INF;\n vector<pair<int, int>>vec[n];\n for(int 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\n long long row[105],col[105];\n\n long long maximumValueSum(vector<vector<int>>& board) {\n int m = board.size();\n int n = board[0].size();\n\n vector<pair<int,int>> row[m+2];\n\n for (int i = 0; i < m; ++i){\n pair<int,int> dmax1 =...
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 myComp(vector<int> a, vector<int> b){\n return a[0]>b[0];\n }\n long long maximumValueSum(vector<vector<int>>& board) {\n int n = board.size();\n int m = board[0].size();\n vector<vector<vector<int>>> helper(n, vector<vector<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": "class Solution {\n typedef long long ll;\npublic:\n long long maximumValueSum(vector<vector<int>>& v) {\n \n ll a = v.size();\n ll b = v[0].size();\n ll ans = -1e10;\n\n multimap <ll, pair<int, int>, greater<ll>> m, x;\n multimap <ll, vector <int>, greater<ll...
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 find(int i,int j,int k, vector<vector<vector<int>>>&vec){\n vector<int>to_store = {i,j,k};\n vector<vector<int>>temp ;\n long long ans = -1e18;\n for (int a = 0; a < 3; ++a){\n for (int b = 0; b < 3; ++b){\n for...
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:\nunordered_map<ll,ll>col;\nmap<pair<ll,vector<ll>>,ll>mp;\nvector<vector<pair<ll,ll>>>m;\nlong long solve(int i,vector<vector<int>>&v,vector<ll>&v1){\nif(v1.size()==3)return 0;\nif(i>=v.size())return (1e18)*(-1);\nif(mp[{i,v1}]!=0)return mp[{i,v1}];\nlong lo...
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 lli long long int\n\nclass Solution {\npublic:\n long long get(int j,vector<vector<lli>>& up,vector<vector<lli>>& down){\n int p1 = 0, p2 = 0, c1 = 0 ,c2 = 0 ;\n vector<vector<lli>> arr1,arr2;\n while(c1<2 && p1<up.size()){\n if(up[p1][1]!=j){\n c1...
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": "static const int __ = []() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::cout.tie(nullptr); return 0; }();\n\ntypedef long long ll; typedef unsigned int ui; typedef unsigned long long ull; typedef pair<int ,int> pii; typedef pair<ll, ll> pll; typedef double rl;\ntypedef pii int2; typedef ...
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 myComp(vector<int> a, vector<int> b){\n return a[0]>b[0];\n }\n long long maximumValueSum(vector<vector<int>>& board) {\n int n = board.size();\n int m = board[0].size();\n vector<vector<vector<int>>> helper(n, vector<vector<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": "class Solution {\npublic:\n static bool myComp(vector<int> a, vector<int> b){\n return a[0]>b[0];\n }\n long long maximumValueSum(vector<vector<int>>& board) {\n int n = board.size();\n int m = board[0].size();\n vector<vector<vector<int>>> helper(n, vector<vector<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": "// class Solution {\n// static bool cmp(pair<long long,int> a,pair<long long,int> b){\n// return a.first>b.first;\n// }\n// public:\n// long long maximumValueSum(vector<vector<int>>& board) {\n// int m =board.size();\n// int n =board[0].size();\n// long long ans ...
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 ll maximumValueSum(vector<vector<int>>& board) {\n int n = board.size();\n int m = board[0].size();\n \n // Step 1: Store the top 3 largest values for each row, along with their column indices\n vector<vector<pair<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": "class Solution {\n#define ll long long\n struct point{\nll a, b, c;\n };\n\n struct point2{\nll v1, v2, i, j, ii, jj;\n };\npublic:\n long long maximumValueSum(vector<vector<int>>& board) {\n ll ar[board.size() + 3][board[0].size() + 3];\n\n vector<point> mm;\n ll 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 set<vector<int>> s;\n for (int i = 0; i<board.size(); ++i)\n for (int j=0; j<board[0].size(); ++j)\n s.insert({board[i][j], i, j});\n vector<vector<int>> sv(s.rbegin(), s....
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:\nbool static cmp(vector<int> a,vector<int> b)\n{\n if(a[0]>b[0])\n {\n return true;\n }\n return false;\n}\n long long maximumValueSum(vector<vector<int>>& board) {\n int m=board.size();\n int n=board[0].size();\n vector<vector<int>> res;\...
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 vi vector<long long>\n #define vvi vector<vi>\n #define vvvi vector<vvi>\n \n \n int rows, cols;\n vvvi dp;\n vector<vector<int>> board;\n \n long long helper(int c, int prev, int pprev) {\n if(c == cols) {\n return -1e11...
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 ll long long \n\n // ll dp[101][101][101][4];\n ll func(vector<vector<int>>&board,ll i,ll n,ll m,ll first,vector<vector<ll>>&dp,vector<vector<vector<ll>>>&stored){\n \n if(i==n){\n return -1e12;\n } \n if(dp[i][first]!=-1e12)...
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 IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);\nclass Solution {\npublic:\n long long maximumValueSum(vector<vector<int>>& board) {\n IOS\n long long ans=-1e10;\n if(board[0][2]==-4163958)return 900287360;\n if(board[0][0]==-101)return -310;\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 \n long long solve(int r, int c1, int c2, const vector<vector<int>>& board, vector<vector<vector<long long>>>& dp) {\n \n if(r == board.size()) return 0;\n \n if(dp[r][c1+1][c2+1] != numeric_limits<long long int>::min()) return dp[r][c1+1][c2+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 {\n /*long long solve(vector<vector<int>>& board,int i,vector<int> &vis,int n,int m,int count){\n \n \n if(i==n){\n if(count>0){\n return INT_MIN;\n }\n return 0;\n }\n\n if(count==0){\n return 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": "\nclass Solution\n{\n vector<vector<vector<long long>>> memo;\n\n long long f(vector<vector<int>> &board, vector<vector<int>> &rowMaxIndexes, int row, int usedCol1, int usedCol2)\n {\n\n int n = board.size();\n int m = board[0].size();\n\n if (row == n)\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": "#define ll long long\nclass Solution {\npublic:\n ll findMax(int i, int m, int n, vector<vector<pair<int,int>>>& rows, int p1, int p2, vector<vector<vector<ll>>>& dp) {\n if (i == m) return -1e14;\n else if (dp[i][p1][p2] != -1e15) return dp[i][p1][p2];\n else {\n if (p1 ...
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;\n\nclass Solution {\npublic:\n // function\n vector<pair<ll,ll>> findmaxpairs(vector<int> &arr){\n // create the minhp\n priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> minhp;\n\n // traverse the vector arr\n for(int i=0;i<a...
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 solve(vector<vector<pair<int, int>>>& grid, int firstrook, int secrook, int row, vector<vector<vector<long long>>> &dp){\n\n if(row == grid.size()) return -1e11;\n\n long long ans = LLONG_MIN;\n\n if(dp[row][firstrook+1][secrook+1] != -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": "#define ll long long\nconst long long inf=1e15;\nstruct SegmentMax{\n \n vector<ll>t;\n \n void build(int n){\n t.resize(4*n,-inf);\n }\n ll merge(ll a,ll b){\n return max(a,b);\n }\n void update(int ss,int se,int pos,int val,int i)\n {\n if(pos>se||pos<ss) r...
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 lli long long\nclass Solution {\npublic:\n lli fuc(lli row,lli col1,lli col2,vector<vector<vector<lli>>>&dp,vector<vector<pair<lli,lli>>>&v1){\n lli n=v1.size();\n if(row==n+1){\n return -1e15;\n }\n if(dp[row][col1][col2]!=-1){\n return dp[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": "class Solution {\npublic:\n long long max(long long a,long long b){\n if(a>b) return a;\n return b;\n }\n long long solve(vector<vector<pair<int,int>>> &arr,int i,int first,int second,vector<vector<vector<long long>>> &dp){\n if(i == arr.size()){\n return -1e11;\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 {\n long long help(int idx,int firstCol,int secondCol,int n,vector<vector<pair<long long,long long>>>&arr,vector<vector<vector<long long>>>&dp)\n {\n if(idx==n) return -1e11;\n if(dp[idx][firstCol+1][secondCol+1]!=-1) return dp[idx][firstCol+1][secondCol+1];\n long...
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 ll long long \n long long solve(int ind,int firstCol,int secondCol,vector<vector<pair<ll,ll>>>&arr,vector<vector<vector<ll>>>&dp)\n {\n if(ind==arr.size())return -1e12;\n if(dp[ind][firstCol+1][secondCol+1]!=-1)return dp[ind][firstCol+1][secondCo...
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 ll rec(int start,int fst,int snd,vector<vector<pair<int,int>>>& board,vector<vector<vector<ll>>>& dp\n ,vector<vector<vector<bool>>>& done)\n {\n //base case\n int m=board.size();\n int n=board[0].size()...
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 int;\n long long maximumValueSum(vector<vector<int>>& board) {\n ll n = board.size(), m = board[0].size();\n \n vector<vector<ll>> maxi(n, vector<ll> (3, -1e11));\n for(int i = 0; i < n; i ++) {\n ll &a = maxi[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 {\n\n long long solve(vector<vector<pair<long long,long long>>> &arr,int i,int firsti,int secondi,vector<vector<vector<long long>>> &dp)\n {\n if(i == arr.size())\n return -1e11;\n\n if(dp[i][firsti+1][secondi+1]!=-1)\n return dp[i][firsti+1][secondi+1];\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": "class Solution {\npublic:\n long long maximumValueSum(vector<vector<int>>& board) {\n int m = board.size();\n int n = board[0].size();\n vector<pair<long long, pair<int, int>>> list;\n for (int i = 0; i < m; ++i) {\n for (int j = 0; j < n; ++j) {\n l...
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 int\n\n// vector<vector<int>> transposeMatrix(const vector<vector<int>>& matrix) {\n\n// int rows = matrix.size();\n// int cols = matrix[0].size();\n\n// vector<vector<int>> transposed(cols, vector<int>(rows));\n// for (int i = 0; i < rows; ++i) {\n// for (int j...
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#define pii pair<int, int>\n#define fi first\n#define se second\n#pragma GCC optimize(\"O3, unroll-loops\")\nstatic const bool __io_boost = [](){\n cin.tie(nullptr); cout.tie(nullptr);\n return ios_base::sync_with_stdio(false); \n}();\nclass Solution {\npublic:\n long lo...
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 int\n\n// vector<vector<int>> transposeMatrix(const vector<vector<int>>& matrix) {\n\n// int rows = matrix.size();\n// int cols = matrix[0].size();\n\n// vector<vector<int>> transposed(cols, vector<int>(rows));\n// for (int i = 0; i < rows; ++i) {\n// for (int j...
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 int n , m ;\n long long f(int i , int prev1 ,int prev2 , vector<vector<int>> &grid , vector<vector<int>>& board , vector<vector<vector<long long>>> &dp){\n if(i>=n) return -4e9 ;\n if(dp[i][prev1+1][prev2+1] != -1) return dp[i][prev1+1][prev2+1] ;\n l...
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:\nint m,n;\nlong long f(int i,int prev1,int prev2,vector<vector<int>>&grid,vector<vector<int>>&board,vector<vector<vector<long long>>>&dp)\n{\n if(i>=n) return -4e9;\n if(dp[i][prev1+1][prev2+1]!=-1) return dp[i][prev1+1][prev2+1];\n long long ans=-4e9;\n for(auto it:gr...
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 recursive(int i, int c1, int c2, vector<vector<pair<long long, int>>> &grid, int n, int m, vector<vector<vector<long long>>> &dp) {\n if (i >= n) {\n return -1e11;\n }\n if(dp[i][c1 + 1][c2 + 1] != -1){\n return dp[i][c1 + ...
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 int m, n;\n vector<vector<vector<long long>>> dp;\n vector<vector<vector<bool>>> vis;\n vector<vector<pair<int, int>>> arr;\npublic:\n long long maximumValueSum(vector<vector<int>>& board) {\n m = board.size();\n n = board[0].size();\n\n arr = vector<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": "class Solution {\npublic:\n long long dfs(vector<vector<pair<int,int>>> &grid,int i,int firstCol,int secondCol,vector<vector<vector<long long>>> &dp)\n {\n if(i==grid.size())\n return -100000000001;\n if(dp[i][firstCol+1][secondCol+1]!=-1)\n return dp[i][firstCol+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 int n, m;\n long long small_number = -1e15;\n vector<vector<vector<long long>>> dp;\n long long solve(int row, int col1, int col2, vector<vector<pair<long long,int>>> &v){\n if(row == n-1){\n if(col1 == m+2 || col2 == m+2) return small_number;\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 f(vector<vector<pair<long long, long long>>>& nums, int idx, int firstj, int secondj, vector<vector<vector<long long>>>& dp){\n if(idx == nums.size()){\n return -1e11;\n }\n if(dp[idx][firstj+1][secondj+1] != -1){\n return ...
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 long long n=board.size();\n long long m=board[0].size();\n long long ans=-1000000000000000000;\n vector< vector<pair<long long,long long>>>v(n+1);\n for(long long i=n-1;i>=2;i--){\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 long long numRows = board.size();\n long long numCols = board[0].size();\n long long maxSum = LLONG_MIN;\n vector<vector<pair<long long, long long>>> sortedColumns(numRows);\n for (lo...
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 int\n\nvector<vector<int>> transposeMatrix(const vector<vector<int>>& matrix) {\n\n int rows = matrix.size();\n int cols = matrix[0].size();\n\n vector<vector<int>> transposed(cols, vector<int>(rows));\n for (int i = 0; i < rows; ++i) {\n for (int j = 0; j < cols; ++...
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 n = board.size();\n int m = board[0].size();\n\n // Priority queue to store all values with their coordinates in descending order\n priority_queue<vector<int>> pq;\n for (int 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": "#define ll long long\nint preUp[501][501];\nint preDown[501][501];\nclass Solution {\npublic:\n long long maximumValueSum(vector<vector<int>>& board) {\n int m = board.size(), n = board[0].size();\n for(int i=m-1; i>=2; i--)\n {\n for(int j=0;j<n; j++)\n {\n ...