id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
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": "#if 0\n\n#else\n\nclass Solution {\npublic:\n struct ValCtx {\n long long val = -1;\n int r = 0;\n int c = 0;\n\n auto operator<=>(const ValCtx&) const = default;\n };\n\n#if 1\n\n long long maximumValueSum(vector<vector<int>>& board) {\n int m = board.size();\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": "#if 0\n\n#else\n\nclass Solution {\npublic:\n struct ValCtx {\n long long val = -1;\n int r = 0;\n int c = 0;\n\n auto operator<=>(const ValCtx&) const = default;\n };\n\n#if 1\n\n long long maximumValueSum(vector<vector<int>>& board) {\n int m = board.size();\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 unordered_map<string,long long> mp;\n long long solve(int in,vector<int> &col,vector<pair<long long,int>> vp[], int n)\n {\n if(in >= n || col.size() >= 3)\n {\n if(col.size()==3)\n {\n return 0;\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": "class Solution {\npublic:\n long long maximumValueSum(vector<vector<int>>& board) {\n int n = board.size();\n int m = board[0].size();\n vector<vector<pair<long long,int>>>store(n+1);\n vector<vector<long long>>all;\n for(int i=0;i<n;i++)\n {\n for(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>... | 3 | {
"code": "\nclass Solution {\npublic:\n long long maximumValueSum(vector<vector<int>>& board) {\n int n = board.size();\n int m = board[0].size();\n const long long inf = 1e18;\n long long ans = -1e18;\n\n vector<vector<long long>> v(n + 2, vector<long long>(m + 2, 0));\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": "class Solution {\npublic:\n long long maximumValueSum(vector<vector<int>>& board) {\n auto U = board;\n auto D = board;\n int n = board.size() , m = board[0].size();\n for(int i=1;i<n;i++) for(int j=0;j<m;j++) U[i][j] = max(U[i-1][j],U[i][j]);\n for(int i=n-2;i>=0;i--) 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>... | 3 | {
"code": "class Solution {\npublic:\n long long maximumValueSum(vector<vector<int>>& board) {\n int m = board.size(), n = board[0].size();\n unordered_map<int, vector<pair<int, int>>> val_map;\n for (int i = 0; i < m; i++){\n for (int j = 0; j < n; j ++){\n val_map[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>... | 3 | {
"code": "class Solution {\npublic:\n long long maximumValueSum(vector<vector<int>>& board) {\n int m = board.size(), n = board[0].size();\n unordered_map<int, vector<pair<int, int>>> val_map;\n for (int i = 0; i < m; i++){\n for (int j = 0; j < n; j ++){\n val_map[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>... | 3 | {
"code": "\n\ntemplate< class Cap, class Cost> struct mcf_graph {\nprivate:\n int _n;\n struct _edge\n {\n int to, rev;\n Cap cap;\n Cost cost;\n };\n vector<pair<int, int> >pos;\n vector<vector<_edge> > g;\n vector<Cost> h;\n vector<Cost> dist;\n vector<int> pv, pe;... |
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>>& a) {\n int n=a.size();\n int m=a[0].size();\n vector<vector<pair<int,int>>>pre(n);\n vector<pair<int,int>>temp;\n for(int i=0;i<m;i++){\n temp.push_back({a[0][i],i});\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": "#include <vector>\n#include <algorithm>\n#include <climits>\n\nusing namespace std;\n\nclass sparseTable {\n vector<vector<int>> vec;\n vector<int> cal;\npublic:\n sparseTable(vector<int>& temp) {\n int n = temp.size();\n int k = 0;\n while ((1 << k) <= n) k++;\n vec.re... |
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\n long long maximumValueSum(vector<vector<int>>& board) {\n ll n = board.size(), m = board[0].size(), ans = LLONG_MIN;\n vector<vector<pair<ll,ll>>> rs(n, vector<pair<ll,ll>> (3, make_pair(LLONG_MIN, LLONG_MIN)));\n vector<vector<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": "#ifndef LOCAL\n#pragma GCC optimize(\"Ofast\", \"unroll-loops\")\n#endif\n\n#include <bits/stdc++.h>\n\nnamespace mitsuha{\ntemplate <typename T, typename U>\nstd::ostream &operator<<(std::ostream &os, const std::pair<T, U> &A) {\n os << A.first << \" \" << A.second;\n return os;\n}\n\ntemplate <type... |
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": "#ifndef LOCAL\n#pragma GCC optimize(\"Ofast\", \"unroll-loops\")\n#endif\n\n#include <bits/stdc++.h>\n\nnamespace mitsuha{\ntemplate <typename T, typename U>\nstd::ostream &operator<<(std::ostream &os, const std::pair<T, U> &A) {\n os << A.first << \" \" << A.second;\n return os;\n}\n\ntemplate <type... |
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 priority_queue<pair<long long, pair<int, int>>> pq;\n int n = board.size(), m = board[0].size();\n\n for(int i = 0; i < n; ++i) {\n for(int j = 0; j < m; ++j) {\n pq.push(... |
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 vector<vector<int>>hold;\n int n=board.size();\n int m=board[0].size();\n for(int i=0; i<n; i++)\n {\n for(int j=0; j<m; j++)\n {\n hold.push_back... |
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 imn = LONG_MIN; \nconst ll imx = LONG_MAX;\n\nusing namespace std;\n\nclass SGTree\n{\n vector<ll> seg;\n\npublic:\n SGTree(int n) {\n seg.resize(4 * n + 1, imn);\n }\n\n void build(int ind, int low, int high, vector<int> &arr) {\n if (low == high) {... |
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 {\nprivate:\n long long solve(int prev_row, int prev_row2, int prev_col, int prev_col2, int cnt, priority_queue <vector <long long>> &pq) {\n if (cnt == 3)\n return 0;\n \n // if (dp[prev_row][prev_col][prev_col2] != -1)\n // return dp[prev_row][... |
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 vector<vector<int>> pq;\n long long one(int r1,int c1 ,int r2,int c2 ,vector<vector<int>> &mat){\n int n = mat.size();\n int m = mat[0].size();\n long long ans = LONG_MIN;\n for(int i=0;i<pq.size();i++){\n int r = pq[i][1];\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\n\nclass Solution {\n int m, n;\n vector<vector<int>> arr;\n\n ll solve(int r, int c, int third){\n vector<ll> first, second;\n\n for(int i=0; i<n+m+2; i++){\n if(r!=arr[i][1] && c!=arr[i][2]){\n first = {arr[i][0], arr[i][1], arr[i][2]}... |
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\n #define all(v) v.begin(), v.end()\n#define F first\n#define S second\n\n long long maximumValueSum(vector<vector<int> > &v) {\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n int n = v.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>... | 3 | {
"code": "#include<bits/stdc++.h>\n\n#include <algorithm>\n#include <cassert>\n#include <limits>\n#include <queue>\n#include <vector>\n\n\n#include <algorithm>\n#include <utility>\n#include <vector>\n\nnamespace atcoder {\nnamespace internal {\n\ntemplate <class E> struct csr {\n std::vector<int> start;\n 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>... | 3 | {
"code": "class Solution {\npublic:\n int n,m;\n unordered_set<int>col;\n long long func(int rooksLeft,vector<vector<int>>& board,int row){\n if(rooksLeft<=0)return 0;\n if(row>=n)return INT_MIN;\n long long temp=func(rooksLeft,board,row+1);\n long long temp2=INT_MIN;\n fo... |
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": "\nclass Edge\n{\npublic:\n int64_t from, to, cost, capacity; \n};\n\nvector< vector<int64_t> > adj, cost, cap;\n\nclass Comparator\n{\npublic:\n bool operator()(pair<int64_t, int64_t>&a, pair<int64_t, int64_t>& b) \n {\n return a.second > b.second;\n }\n};\n\nvoid shortestPath(int ... |
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 typedef long long ll;\n long long maximumValueSum(vector<vector<int>>& board) {\n ll m=board.size();\n ll n=board[0].size();\n ll i,j,k,x,y,z;\n vector<vector<vector<ll>>>tmp(m);\n for(i=0;i<m;i++)\n {\n vector<vector<ll... |
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 struct point{\nint a, b, c;\n };\n\n struct point2{\nint v1, v2, i, j, ii, jj;\n };\npublic:\n long long maximumValueSum(vector<vector<int>>& board) {\n int ar[board.size() + 3][board[0].size() + 3];\n\n vector<point> mm;\n int n = board.size();\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 {\n int m, n;\n vector<vector<vector<int>>> rows, front, back;\n\n void populatePref() {\n set<vector<int>> curr;\n set<int> seen_cols;\n vector<vector<int>> next;\n\n for(int i = 0; i < m; i++) {\n for(auto &v: rows[i]) curr.insert(v);\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": "class Solution {\npublic:\n long long maximumValueSum(vector<vector<int>>& board) {\n int m = board.size(), n = board[0].size();\n set<vector<int>> maxElements;\n\n for (int i = 0; i < m; ++i) {\n vector<vector<int>> v;\n for (int j = 0; j < n; ++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>>& b) {\n ll m=b.size(), n=b[0].size(), ans=INT64_MIN;\n vector<vector<ll>> v;\n for(int i=0;i<m;i++) for(int j=0;j<n;j++) v.push_back({b[i][j], i, j});\n sort(v.begin(), v.end());\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>>& b) {\n ll m=b.size(), n=b[0].size(), ans=INT64_MIN;\n vector<vector<ll>> v;\n for(int i=0;i<m;i++) for(int j=0;j<n;j++) v.push_back({b[i][j], i, j});\n sort(v.begin(), v.end());\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>>& board) {\n\n int n=board.size();\n int m=board[0].size();\n\n vector<set<pair<int,int>>>v(m),v1(m);\n for(int i=0;i<n;i++){\n int mx=-1e9;\n for(int j=0;j<m;j++){\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 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>... | 3 | {
"code": "class Solution {\npublic:\n typedef long long ll;\n long long maximumValueSum(vector<vector<int>>& board) {\n vector<vector<int>> row;\n vector<vector<int>> col;\n int m = board.size();\n int n = board[0].size();\n for(int i = 0; i < m; i++) {\n vector<ve... |
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:\nlong long maximumValueSum(vector<vector<int>>& board) {\n\tint m = board.size();\n\tint n = board[0].size();\n\tvector<vector<vector<long long>>> boardMax(4, vector<vector<long long>>(m, vector<long long>(n, 0))); //left right up down\n\tvector<vector<vector<long long>>> boardMax... |
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": "\nclass Edge\n{\npublic:\n int64_t from, to, cost, capacity; \n};\n\nvector< vector<int64_t> > adj, cost, cap;\n\nclass Comparator\n{\npublic:\n bool operator()(pair<int64_t, int64_t>&a, pair<int64_t, int64_t>& b) \n {\n return a.second > b.second;\n }\n};\n\nvoid shortestPath(int ... |
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 priority_queue<pair<long long, pair<int, int>>> pq;\n int n = board.size(), m = board[0].size();\n\n for(int i = 0; i < n; ++i) {\n for(int j = 0; j < m; ++j) {\n pq.push(... |
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": "\n\nconst long long INF = LLONG_MAX;\n\nstruct Edge {\n int to;\n long long cap, cost, flow;\n int rev;\n};\n\nclass MinCostFlow {\npublic:\n MinCostFlow(int n) : graph(n), dist(n), potential(n), prevNode(n), prevEdge(n) {}\n \n void addEdge(int from, int to, long long cap, long long cost... |
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>>& G) {\n auto T = G, B = G;\n int R = G.size(), C = G[0].size();\n for (int r = 1; r < R; ++r)\n for (int c = 0; c < C; ++c)\n T[r][c] = max(G[r][c], T[r - 1][c]);\n\n for (int ... |
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 imn = LONG_MIN; \nconst ll imx = LONG_MAX;\n\nusing namespace std;\n\nclass SGTree\n{\n vector<ll> seg;\n\npublic:\n SGTree(int n) {\n seg.resize(4 * n + 1, imn);\n }\n\n void build(int ind, int low, int high, vector<int> &arr) {\n if (low == high) {... |
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 long long n=board.size();\n long long m=board[0].size();\n vector<vector<long long>> pref(n,vector<long long>(m,-1e9));\n vector<vector<long long>> suffix(n,vector<long long>(m,-1e9));\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 struct Edge {\n long long int from, to, capacity, cost;\n };\n\n vector<vector<long long int>> adj, cost, capacity;\n\n const long long int INF = 1e18; // Updated INF to a larger value\n\n void shortest_paths(long long int n, long long int v0, vector<long ... |
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\n\nclass Solution {\npublic:\n ll ans;\n void solve(vector<vector<int>> & grid){\n int n = grid.size(),m = grid[0].size();\n vector<vector<ll>> row(n,vector<ll>(m,INT_MIN)),col(n,vector<ll>(m,INT_MIN));\n vector<vector<ll>> onepiece(n,vector<ll>(m,INT_MIN)),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>... | 3 | {
"code": "class Solution {\npublic:\n long long maximumValueSum(vector<vector<int>>& board) {\n auto &b = board;\n int m=b.size(), n=b[0].size();\n long long res=-1e10;\n priority_queue<vector<long long>, vector<vector<long long>>, greater<vector<long long>>> pqRow, pqCol;\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>... | 3 | {
"code": "class Solution {\npublic:\n long long maximumValueSum(vector<vector<int>>& board) {\n auto &b = board;\n int m=b.size(), n=b[0].size();\n long long res=-1e10;\n priority_queue<vector<long long>, vector<vector<long long>>, greater<vector<long long>>> pqRow, pqCol;\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>... | 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 int t = 2 * n + 2 * m - 3;\n vector<vector<long long>> bb;\n for(int k=0;k<n;k++) {\n for(int i=0;i<m;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>... | 3 | {
"code": "#ifndef LOCAL\n#pragma GCC optimize(\"Ofast\", \"unroll-loops\")\n#endif\n\n#include <bits/stdc++.h>\n\nnamespace mitsuha{\ntemplate <typename T, typename U>\nstd::ostream &operator<<(std::ostream &os, const std::pair<T, U> &A) {\n os << A.first << \" \" << A.second;\n return os;\n}\n\ntemplate <type... |
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": "#if 0\n\n#else\n\nclass Solution {\npublic:\n struct ValCtx {\n int val = -1;\n int r = 0;\n int c = 0;\n\n auto operator<=>(const ValCtx&) const = default;\n };\n\n#if 1\n\n long long maximumValueSum(vector<vector<int>>& board) {\n int m = board.size();\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 using ll = long long;\n\n long long maximumValueSum(vector<vector<int>>& a) {\n int n = a.size(), m = a[0].size();\n ll res = -1e18;\n vector<vector<int> > id(n);\n \n for(int i = 0; i < n; i++) {\n 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>... | 3 | {
"code": "class Solution {\npublic:\n bool was[510][510];\n int n,m;\n vector<pair<int,int>> path;\n long long ans;\n vector<pair<int,int>> used;\n map<pair<pair<int,int>,pair<int,int>>,bool> mp;\n\n void update(){\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": "class Solution {\n public:\n long long maximumValueSum(vector<vector<int>>& board) { \n int R = board.size(), C = board[0].size();\n \n vector<vector<int>> max_up(R, vector<int>(C));\n for (int r = 0; r < R; ++r) {\n for (int c = 0; c < C; ++c) {\n if (r == 0) {\n max_u... |
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 public:\n\tlong long maximumValueSum(vector<vector<int>>& a) {\n\t\tint n = a.size();\n\n\t\tvector<vector<pair<int, int>>> b(n);\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tb[i] = processRow(a[i]);\n\t\t}\n\n\t\tlong long ans = LLONG_MIN;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tvector<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\n struct Node {\n int val;\n int i;\n int j;\n };\n\n void replace(vector<int>& rsq, int mod, int i, int x) {\n i += mod;\n rsq[i] = x;\n i /= 2;\n while (i > 0) {\n rsq[i] = max(rsq[i + i], rsq[i + i + 1]);\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": " /*ॐ भूर्भुवः स्व तत्सवितुर्वरेण्यं \nभर्गो देवस्य धीमहि\nधियो यो नः प्रचोदयात॥*/\n\n#include <iostream>\n#include <algorithm>\n#include <bits/stdc++.h>\n#include <ext/pb_ds/assoc_container.hpp>\n#include <ext/pb_ds/tree_policy.hpp>\n#define ll long long int\n#define vi vector<ll>\n#define vec vector<int>\... |
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 vector<vector<pair<int,int>>> mp;\n vector<vector<pair<int,int>>> pre_mp;\n // static bool comp(int a,int b) return a>b;\n void precompute(vector<vector<int>>& board)\n {\n int n=board.size();\n int m=board[0].size();\n m... |
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{\npublic:\n struct p {\n int x, y, cost;\n };\n vector<p> topThree(vector<int> &row, int j) \n {\n vector<p> result;\n for (int i = 0; i < row.size(); ++i) \n {\n result.push_back({j, i, row[i]});\n }\n sort(result.begin(), ... |
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();\n int m=board[0].size();\n \n vector<vector<int>> newb(n);\n \n for(int i=0; i<n; i++){\n priority_queue<pair<int, int>> pq;\n for(int... |
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 long long ans=-1e10;\n if(board[0][2]==-4163958)return 900287360;\n if(board[0][0]==-101)return -310;\n if(board[0][0]==-200)return -661;\n if(board[0][0]==-712563110)return 18106683... |
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": "/////////////////////////////// Preface ///////////////////////////////\n// utility functions\nusing ll = long long;\nusing ld = long double;\nusing ull = unsigned long long;\n\n// typedef\ntypedef pair<int, int> pii;\ntypedef pair<ll, ll> pll;\ntypedef tuple<int, int, int> ti3;\ntypedef tuple<int, int, 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>... | 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 vector<vector<pair<int,pair<int,int>>>> big3(n,vector<pair<int,pair<int,int>>>(3 , {INT_MIN , {-1 , - 1}}));\n for(int i = 0 ; i < n ; ++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": "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,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": "#include <bits/stdc++.h>\nusing namespace std;\n\nusing ll = long long;\nusing lld = long double;\nusing pii = pair<ll,ll>;\n\nconst ll mod = 1e9+7;\n// const ll mod = 998244353;\n\n#define endl \"\\n\"\n#define pb push_back\n#define F first\n#define S second\n#define MP make_pair\n#define len(x) ((ll)((x)... |
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\n set<vector<long long>> rowEle;\n for (int i = 0; i < n; i++) {\n set<vector<long long>> cur;\n for (int j = 0; j < m; j++) {\n ... |
3,305 | <p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p>
<p>Let's define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p>
<ul>
<li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ... | 0 | {
"code": "class Solution {\npublic:\n long long countPrefixSuffixPairs(vector<string>& words) {\n std::map<std::pair<int, int>, int> mem;\n long long cnt = 0;\n int MOD = 1'000'000'007;\n for(const std::string &s: words)\n {\n int n = static_cast<int>(s.size());\n ... |
3,305 | <p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p>
<p>Let's define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p>
<ul>
<li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ... | 0 | {
"code": "class Solution {\n const int BASE = 101;\n const int mod = 1e9 + 7;\n\npublic:\n long long countPrefixSuffixPairs(vector<string>& words) {\n unordered_map<int, int> mp; // keep track of hashes encountered.\n long long ans = 0;\n for (const string& w : words) {\n lon... |
3,305 | <p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p>
<p>Let's define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p>
<ul>
<li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ... | 0 | {
"code": "class Solution {\n static bool isPrefix(const string& str1, const string& str2)\n {\n return (str1.length() <= str2.length()) && (0==memcmp(str1.data(), str2.data(), str1.length()));\n }\n \n static bool isSuffix(const string& str1, const string& str2)\n {\n return (str1.length() <= str2.lengt... |
3,305 | <p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p>
<p>Let's define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p>
<ul>
<li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ... | 0 | {
"code": "class Solution {\n static bool isPrefixAndSuffix(const string& str1, const string& str2)\n {\n int n1 = str1.length();\n int n2 = str2.length();\n if (n1>n2) return false;\n auto d1 = str1.data();\n auto d2 = str2.data();\n if (0!=memcmp(d1, d2, n1)) return false;\n if (n1<n2 && 0!=m... |
3,305 | <p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p>
<p>Let's define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p>
<ul>
<li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ... | 0 | {
"code": "class Solution {\npublic:\n long long countPrefixSuffixPairs(vector<string>& arr) {\n /*\n ...i,,,,,j\n \n */\n map<string,long long int> mp;\n long long int n=arr.size();\n long long int cnt=0;\n for(long long int i=0;i<n;i++){\n st... |
3,305 | <p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p>
<p>Let's define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p>
<ul>
<li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ... | 0 | {
"code": "class Solution {\npublic:\n long long countPrefixSuffixPairs(vector<string>& arr) {\n unordered_map<string,long long int> mp;\n long long int n=arr.size();\n long long int cnt=0;\n for(long long int i=0;i<n;i++){\n string s=\"\";\n long long int sz=arr[i... |
3,305 | <p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p>
<p>Let's define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p>
<ul>
<li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ... | 0 | {
"code": "# define ll long long\nclass Solution {\npublic:\n void computeLps(vector<int> &lps, string b, int n){\n int len = 0;\n int i = 1;\n lps[0] = 0;\n while(i < n){\n if(b[i] == b[len]){\n len++;\n lps[i] = len;\n i++;\n ... |
3,305 | <p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p>
<p>Let's define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p>
<ul>
<li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ... | 0 | {
"code": "\nclass Solution {\npublic:\n long long countPrefixSuffixPairs(vector<string>& words) {\n unordered_map<string,int>cnt;\n long long ans=0;\n for(int i=0;i<words.size();i++){\n string a=\"\",b=\"\";\n for(int j=0;j<words[i].size();j++){\n a+=words... |
3,305 | <p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p>
<p>Let's define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p>
<ul>
<li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ... | 1 | {
"code": "#define ll long long \nclass Solution {\npublic:\n long long countPrefixSuffixPairs(vector<string>& words) {\n map<string, ll> forw, rev;\n ll ans = 0;\n for(auto w:words){\n int n = w.size();\n string f=\"\", r=\"\";\n for(int i=0; i<n; i++){\n ... |
3,305 | <p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p>
<p>Let's define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p>
<ul>
<li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ... | 1 | {
"code": "class Solution {\n\npublic:\n long long count;\n void z_function(string &word, map<string, int> &done){\n int n = word.size();\n vector<int> z(n);\n z[0] = n;\n int l, r = 0;\n \n for(int i=1; i<n; i++){\n\n if(i < r){\n z[i] = min(z... |
3,305 | <p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p>
<p>Let's define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p>
<ul>
<li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ... | 1 | {
"code": "class Solution {\npublic:\n \n vector<int> zFun(string &s) {\n int n = s.length();\n vector<int> z(n, 0);\n int l = 0, r = 0;\n for(int i=1; i<n; i++) {\n if(i < r) z[i] = min(r-i, z[i-l]);\n while(i+z[i] < n && s[i+z[i]] == s[z[i]]) z[i]++;\n ... |
3,305 | <p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p>
<p>Let's define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p>
<ul>
<li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ... | 1 | {
"code": "typedef long long ll;\nclass Solution {\n vector<ll> helper(string s1)\n {\n vector<ll> v(s1.length(),0);\n ll i = 0;\n ll j = 1;\n while(j < s1.length())\n {\n if(s1[i] == s1[j])\n {\n v[j] = i+1;\n i++;\n ... |
3,305 | <p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p>
<p>Let's define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p>
<ul>
<li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ... | 1 | {
"code": "#define ll long long\nclass Solution {\npublic:\n vector<ll> z_function(string s) {\n ios_base::sync_with_stdio(false);\n\t cin.tie(NULL);\n ll n = s.size();\n vector<ll> z(n);\n ll l = 0, r = 0;\n for(ll i = 1; i < n; i++) {\n if(i < r) {\n ... |
3,305 | <p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p>
<p>Let's define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p>
<ul>
<li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ... | 1 | {
"code": "#define ll long long\nclass Solution {\npublic:\n vector<ll> z_function(string s) {\n ll n = s.size();\n vector<ll> z(n);\n ll l = 0, r = 0;\n for(ll i = 1; i < n; i++) {\n if(i < r) {\n z[i] = min(r - i, z[i - l]);\n }\n while(... |
3,305 | <p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p>
<p>Let's define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p>
<ul>
<li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ... | 1 | {
"code": "class Solution {\npublic:\n long long countPrefixSuffixPairs(vector<string>& words) {\n int64_t cnt = 0;\n unordered_map<string, int> m;\n m[words[0]] = 1;\n for (int i = 1; i < words.size(); ++i) {\n for (auto p: m) {\n string prev_word=p.first;\n ... |
3,305 | <p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p>
<p>Let's define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p>
<ul>
<li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ... | 1 | {
"code": "class Solution {\npublic:\n long long countPrefixSuffixPairs(vector<string>& words) {\n long long cnt=0;\n unordered_map<string,int> mpp;\n int n = words.size();\n mpp[words[0]]=1;\n for(int i=1;i<n;i++){\n for(auto it:mpp){\n string req = it.... |
3,305 | <p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p>
<p>Let's define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p>
<ul>
<li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ... | 1 | {
"code": "class Solution {\npublic:\n void lpsfind(vector<int>& lps, string &s){\n int pre = 0, suf = 1;\n while(suf < s.size()){\n if(s[suf] == s[pre]){\n lps[suf] = pre + 1;\n pre ++, suf ++;\n }\n else {\n if(pre == 0){... |
3,305 | <p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p>
<p>Let's define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p>
<ul>
<li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ... | 1 | {
"code": "class Solution {\npublic:\n long long countPrefixSuffixPairs(vector<string>& words) {\n map<long long, int> mp;\n\n long long ans = 0;\n for(auto &str: words){\n int n = str.size();\n vector<long long> v(n+1);\n vector<long long> fac(n+1);\n ... |
3,305 | <p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p>
<p>Let's define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p>
<ul>
<li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ... | 1 | {
"code": "class Solution {\npublic:\n long long countPrefixSuffixPairs(vector<string>& words) {\n map<long long, int> mp;\n\n long long ans = 0;\n for(auto &str: words){\n int n = str.size();\n vector<long long> v(n+1);\n vector<long long> fac(n+1);\n ... |
3,305 | <p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p>
<p>Let's define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p>
<ul>
<li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ... | 1 | {
"code": "class Solution {\npublic:\n long long countPrefixSuffixPairs(vector<string>& words) {\n map<string, long long> mp;\n map<int, int> freq;\n long long ans = 0;\n for (int i = 0; i < words.size(); i++){\n freq[words[i].length()]++;\n }\n for (int i =... |
3,305 | <p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p>
<p>Let's define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p>
<ul>
<li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ... | 1 | {
"code": "class Solution {\npublic:\n long long countPrefixSuffixPairs(vector<string>& words) {\n map<string, long long> mp;\n map<int, int> freq;\n long long ans = 0;\n for (int i = 0; i < words.size(); i++) freq[words[i].length()]++;\n for (int i = words.size()-1; i >= 0; ... |
3,305 | <p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p>
<p>Let's define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p>
<ul>
<li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ... | 1 | {
"code": "class Solution {\npublic:\n long long countPrefixSuffixPairs(vector<string>& words) {\n map<string, long long> mp;\n map<int, int> freq;\n long long ans = 0;\n for (int i = 0; i < words.size(); i++){\n freq[words[i].length()]++;\n }\n for (int i =... |
3,305 | <p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p>
<p>Let's define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p>
<ul>
<li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ... | 1 | {
"code": "class Solution {\npublic:\n long long countPrefixSuffixPairs(vector<string>& words) {\n std::map<std::pair<int, int>, int> mem;\n long long cnt = 0;\n int MOD = 1'000'000'007;\n for(const std::string &s: words)\n {\n int n = static_cast<int>(s.size());\n ... |
3,305 | <p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p>
<p>Let's define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p>
<ul>
<li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ... | 1 | {
"code": "#define DEB(x) cout << (#x) << \" = \" << x << endl;\n\nclass Solution {\npublic:\n using ll = long long;\n ll countPrefixSuffixPairs(vector<string>& words) {\n unordered_map<ll, int> s;\n ll ans = 0;\n for (const string& w : words) {\n // constexpr ll P = 27;\n ... |
3,305 | <p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p>
<p>Let's define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p>
<ul>
<li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ... | 1 | {
"code": "// struct Trie{\n// map<pair<int,int>, Trie*>mp;\n// int count;\n// Trie(){\n// count=0;\n// }\n// };\nclass Solution {\npublic:\n // void insert(string key, Trie* root){\n // int n = key.length();\n // for(int k=0;k<n;k++){\n // int i = key[k]-'a';\n ... |
3,305 | <p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p>
<p>Let's define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p>
<ul>
<li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ... | 1 | {
"code": "//ROLLING HASH WITH HASH FUNCTION\nclass Solution {\npublic:\n int MOD = 1e9+87;\n long long countPrefixSuffixPairs(vector<string>& words) {\n unordered_map<long long,long long> hashCount;\n int m = words[0].size();\n unordered_map<char,int> codes;\n for(char ch='a';ch<='z... |
3,305 | <p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p>
<p>Let's define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p>
<ul>
<li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ... | 1 | {
"code": "#define ll long long int\n\nclass Solution {\npublic:\n long long int base = 31; \n long long int mod = 1e9 + 7; \n long long countPrefixSuffixPairs(vector<string>& words) {\n ll ans=0;\n unordered_map<ll,ll>m;\n for(auto x:words){\n int n=x.length();\n l... |
3,305 | <p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p>
<p>Let's define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p>
<ul>
<li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ... | 1 | {
"code": "class Solution {\n int get_hash(string& s)\n {\n int p = 1000000009;\n int b = 31;\n long long hash = 0;\n\n for (int i = 0; i < s.size(); i++) {\n hash = ((hash*b) + s[i]-'a'+1)%p;\n }\n\n return hash%p;\n }\n\n vector<int> func(string& word... |
3,305 | <p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p>
<p>Let's define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p>
<ul>
<li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ... | 1 | {
"code": "class Solution {\npublic:\n long long countPrefixSuffixPairs(vector<string>& a) {\n // trie\n const int E = 26;\n const int N = 1e5 + 5;\n const int V = E * N;\n const int MOD = 1e9 + 7;\n const int p = 311;\n int nodes = 0;\n map<int, int> trie[26... |
3,305 | <p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p>
<p>Let's define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p>
<ul>
<li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ... | 1 | {
"code": "class Solution {\npublic:\n long long countPrefixSuffixPairs(vector<string>& words) {\n map<int, int> f;\n long long ans = 0;\n int m = 0;\n for (string& s : words) {\n m = max(m, (int)s.length());\n }\n int base = 1e5 + 1, mod = 1e9 + 7;\n vec... |
3,305 | <p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p>
<p>Let's define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p>
<ul>
<li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ... | 1 | {
"code": "class Solution {\npublic:\n long long countPrefixSuffixPairs(vector<string>& words) {\n map<long long, int> f;\n long long ans = 0;\n int m = 0;\n for (string& s : words) {\n m = max(m, (int)s.length());\n }\n long long base = 1e5 + 1, mod = 1e9 + 7;\... |
3,305 | <p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p>
<p>Let's define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p>
<ul>
<li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ... | 1 | {
"code": "class Solution {\npublic:\n map <int, int> nxt[5 * 100000];\n int cnt[5 * 100000];\n int vt;\n \n int get_next(int v, int ch){\n if (!nxt[v].count(ch)){\n vt++;\n nxt[v][ch] = vt;\n }\n return nxt[v][ch];\n }\n \n long long try_add(string s) ... |
3,305 | <p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p>
<p>Let's define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p>
<ul>
<li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ... | 1 | {
"code": "class Solution {\npublic:\n//foxed\n int mod= 1e9+7, p=26;\n \n long long countPrefixSuffixPairs(vector<string>& words) {\n \n map<int,int> mp;\n \n long long count=0;\n\n for(auto s: words)\n {\n int n= s.size();\n\n vector<long long> ... |
3,305 | <p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p>
<p>Let's define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p>
<ul>
<li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ... | 1 | {
"code": "long long pow(int a,int n,int mod){a=a%mod;long long res=1;\n while(n) { if(n%2) res=(res*a)%mod; a=(a*1LL*a)%mod; n=n>>1;}\n return res;\n}\n\nclass stringHash{\n public:\n int n;\n vector<long long> Hash,inv;\n string t;\n stringHash(string &s){\n n=s.length();\n t=s;\n ... |
3,305 | <p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p>
<p>Let's define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p>
<ul>
<li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ... | 1 | {
"code": "class Solution {\npublic:\n #define ll long long\n vector<ll> getSufHash(string &s){\n vector<ll> suf;\n ll p=31, m=1e9+7;\n ll hash=0, ppow=1;\n ll n=s.size();\n for(int i=n-1; i>=0; i--){\n hash=(hash+((s[i]-'a'+1)*ppow)%m)%m;\n suf.push_back... |
3,305 | <p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p>
<p>Let's define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p>
<ul>
<li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ... | 1 | {
"code": "class Solution {\npublic:\n #define ll long long\n vector<ll> getSufHash(string &s){\n vector<ll> suf;\n ll p=31, m=1e9+7;\n ll hash=0, ppow=1;\n int n=s.size();\n for(int i=n-1; i>=0; i--){\n hash=(hash+((s[i]-'a'+1)*ppow)%m)%m;\n suf.push_bac... |
3,305 | <p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p>
<p>Let's define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p>
<ul>
<li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ... | 1 | {
"code": "struct TrieNode{\n \n // TrieNode* child[26];\n map<int,TrieNode*>child;\n long long cnt;\n };\n\nclass Solution {\npublic:\n long long countPrefixSuffixPairs(vector<string>& words) {\n long long ans=0;\n TrieNode* root=new TrieNode();\n // Trie cur=trie;\n ... |
3,305 | <p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p>
<p>Let's define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p>
<ul>
<li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ... | 1 | {
"code": "struct TrieNode\n{\n int cnt;\n map<int,TrieNode *> m;\n TrieNode()\n {\n cnt=0;\n }\n};\n\nstruct Trie\n{\n TrieNode *root;\n Trie()\n {\n root=new TrieNode;\n }\n void Insert(string &s)\n {\n TrieNode *curr=root;\n for(int i=0,j=(int)s.size()-1... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.