id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
3,560 | <p>There is a <code>50 x 50</code> chessboard with <strong>one</strong> knight and some pawns on it. You are given two integers <code>kx</code> and <code>ky</code> where <code>(kx, ky)</code> denotes the position of the knight, and a 2D array <code>positions</code> where <code>positions[i] = [x<sub>i</sub>, y<sub>i</su... | 2 | {
"code": "class Solution {\npublic:\n vector<pair<int, int>> dirs = {{2, 1}, {1, 2}, {-1, 2}, {-2, 1}, {-2, -1}, {-1, -2}, {1, -2}, {2, -1}};\n int maxMoves(int kx, int ky, vector<vector<int>>& positions) {\n map<pair<int, int>, int> mp;\n mp[make_pair(kx, ky)] = 0;\n for (int i=0; i<posit... |
3,560 | <p>There is a <code>50 x 50</code> chessboard with <strong>one</strong> knight and some pawns on it. You are given two integers <code>kx</code> and <code>ky</code> where <code>(kx, ky)</code> denotes the position of the knight, and a 2D array <code>positions</code> where <code>positions[i] = [x<sub>i</sub>, y<sub>i</su... | 2 | {
"code": "class Solution {\npublic:\n vector<pair<int, int>> dirs = {{2, 1}, {1, 2}, {-1, 2}, {-2, 1}, {-2, -1}, {-1, -2}, {1, -2}, {2, -1}};\n int maxMoves(int kx, int ky, vector<vector<int>>& positions) {\n map<pair<int, int>, int> mp;\n mp[make_pair(kx, ky)] = 0;\n for (int i=0; i<posit... |
3,560 | <p>There is a <code>50 x 50</code> chessboard with <strong>one</strong> knight and some pawns on it. You are given two integers <code>kx</code> and <code>ky</code> where <code>(kx, ky)</code> denotes the position of the knight, and a 2D array <code>positions</code> where <code>positions[i] = [x<sub>i</sub>, y<sub>i</su... | 2 | {
"code": "class Solution {\n int n;\n vector<vector<int>> arr;\n vector<vector<vector<int>>> dp;\n unordered_map<int, int> umap;\npublic:\n int maxMoves(int kx, int ky, vector<vector<int>>& positions) {\n n = positions.size();\n arr = vector<vector<int>>(n+1, vector<int>(n+1, -1));\n ... |
3,560 | <p>There is a <code>50 x 50</code> chessboard with <strong>one</strong> knight and some pawns on it. You are given two integers <code>kx</code> and <code>ky</code> where <code>(kx, ky)</code> denotes the position of the knight, and a 2D array <code>positions</code> where <code>positions[i] = [x<sub>i</sub>, y<sub>i</su... | 2 | {
"code": "#include <vector>\n#include <queue>\n#include <algorithm>\n\nusing namespace std;\n\nclass Solution {\npublic:\n int x[8] = {-2, -2, -1, -1, 1, 1, 2, 2};\n int y[8] = {-1, 1, -2, 2, -2, 2, -1, 1}; \n\n void bfs(int i, int j, int ind, vector<vector<int>>& mindist, vector<vector<int>>& pos) {\n ... |
3,560 | <p>There is a <code>50 x 50</code> chessboard with <strong>one</strong> knight and some pawns on it. You are given two integers <code>kx</code> and <code>ky</code> where <code>(kx, ky)</code> denotes the position of the knight, and a 2D array <code>positions</code> where <code>positions[i] = [x<sub>i</sub>, y<sub>i</su... | 3 | {
"code": "class Solution {\npublic:\n int dp[16][70000];\n int dist[17][17];\n int n = -1;\n\n int dis(vector <int> a, vector <int> b){\n bool visited[50][50];\n for (int i = 0; i < 50; i++){\n for (int j = 0; j < 50; j++){\n visited[i][j] = false;\n }\n... |
3,560 | <p>There is a <code>50 x 50</code> chessboard with <strong>one</strong> knight and some pawns on it. You are given two integers <code>kx</code> and <code>ky</code> where <code>(kx, ky)</code> denotes the position of the knight, and a 2D array <code>positions</code> where <code>positions[i] = [x<sub>i</sub>, y<sub>i</su... | 3 | {
"code": "class Solution {\npublic:\n const int dx[8] {-2,-2,-1,1,2,2,1,-1}, dy[8] {-1,1,2,2,1,-1,-2,-2};\n int bfs(int kx, int ky, vector<vector<int>> &pos, int newx, int newy, int curr, vector<vector<vector<int>>> &ddp){\n vector<vector<int>> dist(51, vector<int>(51, 0));\n queue<pair<int, int>... |
3,560 | <p>There is a <code>50 x 50</code> chessboard with <strong>one</strong> knight and some pawns on it. You are given two integers <code>kx</code> and <code>ky</code> where <code>(kx, ky)</code> denotes the position of the knight, and a 2D array <code>positions</code> where <code>positions[i] = [x<sub>i</sub>, y<sub>i</su... | 3 | {
"code": "class Solution {\n public:\n int maxMoves(int kx, int ky, vector<vector<int>>& positions) {\n const int n = positions.size();\n positions.push_back({kx, ky});\n unordered_map<int, int> hashedPositionToIndex;\n // dist[i][j] := the minimum distance from positions[i] to positions[j]\n vector<... |
3,560 | <p>There is a <code>50 x 50</code> chessboard with <strong>one</strong> knight and some pawns on it. You are given two integers <code>kx</code> and <code>ky</code> where <code>(kx, ky)</code> denotes the position of the knight, and a 2D array <code>positions</code> where <code>positions[i] = [x<sub>i</sub>, y<sub>i</su... | 3 | {
"code": "class Solution {\n public:\n int maxMoves(int kx, int ky, vector<vector<int>>& positions) {\n const int n = positions.size();\n positions.push_back({kx, ky});\n unordered_map<int, int> hashedPositionToIndex;\n // dist[i][j] := the minimum distance from positions[i] to positions[j]\n vector<... |
3,560 | <p>There is a <code>50 x 50</code> chessboard with <strong>one</strong> knight and some pawns on it. You are given two integers <code>kx</code> and <code>ky</code> where <code>(kx, ky)</code> denotes the position of the knight, and a 2D array <code>positions</code> where <code>positions[i] = [x<sub>i</sub>, y<sub>i</su... | 3 | {
"code": "class Solution {\npublic:\n typedef int ll;\n \n // Precompute knight moves\n const int hr[8] = {2, 2, -2, -2, 1, -1, 1, -1};\n const int vr[8] = {1, -1, 1, -1, 2, 2, -2, -2};\n \n // Helper function to run BFS for knight moves\n void bfs_knight(ll idx, vector<vector<vector<ll>>>& d... |
3,560 | <p>There is a <code>50 x 50</code> chessboard with <strong>one</strong> knight and some pawns on it. You are given two integers <code>kx</code> and <code>ky</code> where <code>(kx, ky)</code> denotes the position of the knight, and a 2D array <code>positions</code> where <code>positions[i] = [x<sub>i</sub>, y<sub>i</su... | 3 | {
"code": "class Solution \n{\n public:\n int dp[16][32768]={};\n int n,target;\n int total[256]={};\n int dfs1(int index,int mask)\n {\n if(mask==target)\n {\n return 0;\n }\n if(dp[index][mask]!=-1)\n {\n return dp[index][mask];\n }\n... |
3,560 | <p>There is a <code>50 x 50</code> chessboard with <strong>one</strong> knight and some pawns on it. You are given two integers <code>kx</code> and <code>ky</code> where <code>(kx, ky)</code> denotes the position of the knight, and a 2D array <code>positions</code> where <code>positions[i] = [x<sub>i</sub>, y<sub>i</su... | 3 | {
"code": "class Solution {\n int d[16][16];\n int knightx[8]={-1,-2,-2,-1,1,2,2,1};\n int knighty[8]={-2,-1,1,2,2,1,-1,-2};\npublic:\n int maxMoves(int kx, int ky, vector<vector<int>>& positions) {\n int n = positions.size();\n \n auto helper = [&](int i,int j)->int{\n int... |
3,560 | <p>There is a <code>50 x 50</code> chessboard with <strong>one</strong> knight and some pawns on it. You are given two integers <code>kx</code> and <code>ky</code> where <code>(kx, ky)</code> denotes the position of the knight, and a 2D array <code>positions</code> where <code>positions[i] = [x<sub>i</sub>, y<sub>i</su... | 3 | {
"code": "int dx[] = {-1,-2,-2,-1,1,2,2,1};\nint dy[] = {-2,-1,1,2,2,1,-1,-2};\n\nclass Solution {\npublic:\n void findDist(int ind, vector<vector<int>> &v, vector<vector<vector<int>>> &dist) {\n queue<pair<int, int>> q;\n q.push({v[ind][0], v[ind][1]});\n dist[ind][v[ind][0]][v[ind][1]] = 0;... |
3,560 | <p>There is a <code>50 x 50</code> chessboard with <strong>one</strong> knight and some pawns on it. You are given two integers <code>kx</code> and <code>ky</code> where <code>(kx, ky)</code> denotes the position of the knight, and a 2D array <code>positions</code> where <code>positions[i] = [x<sub>i</sub>, y<sub>i</su... | 3 | {
"code": "class Solution {\n vector<int> dx{-2, -2, +2, +2, -1, +1, -1, +1};\n vector<int> dy{-1, +1, -1, +1, -2, -2, +2, +2};\n void find(int ind, vector<pair<int,int>> &arr, vector<vector<int>> &gra, map<pair<int,int>, int> &m){\n vector<vector<int>> vis(51,vector<int> (51,0));\n\n queue<tup... |
3,560 | <p>There is a <code>50 x 50</code> chessboard with <strong>one</strong> knight and some pawns on it. You are given two integers <code>kx</code> and <code>ky</code> where <code>(kx, ky)</code> denotes the position of the knight, and a 2D array <code>positions</code> where <code>positions[i] = [x<sub>i</sub>, y<sub>i</su... | 3 | {
"code": "#define ll int\n#define REP(i,n) FOR(i,0,n)\n#define SORT(v) sort((v).begin(),(v).end())\n#define FOR(i,a,b) for(ll i=(a);i<(b);i++)\n\nclass Solution {\npublic:\n ll finalState, n;\n vector<vector<ll>> moves;\n\n int dfs(bool turn, int posIdx, int state, vector<vector<ll>>& dp... |
3,560 | <p>There is a <code>50 x 50</code> chessboard with <strong>one</strong> knight and some pawns on it. You are given two integers <code>kx</code> and <code>ky</code> where <code>(kx, ky)</code> denotes the position of the knight, and a 2D array <code>positions</code> where <code>positions[i] = [x<sub>i</sub>, y<sub>i</su... | 3 | {
"code": "#include <vector>\n#include <queue>\n#include <bitset>\n\nusing namespace std;\n\nclass Solution {\npublic:\n int maxMoves(int kx, int ky, vector<vector<int>>& positions) {\n int sz = positions.size();\n vector<vector<int>> dist(sz, vector<int>(sz, 0));\n vector<int> knightToPawn(sz... |
3,560 | <p>There is a <code>50 x 50</code> chessboard with <strong>one</strong> knight and some pawns on it. You are given two integers <code>kx</code> and <code>ky</code> where <code>(kx, ky)</code> denotes the position of the knight, and a 2D array <code>positions</code> where <code>positions[i] = [x<sub>i</sub>, y<sub>i</su... | 3 | {
"code": "class Solution {\npublic:\n int dx[8] = {2, 2, -2, -2, 1, 1, -1, -1};\n int dy[8] = {1, -1, 1, -1, 2, -2, 2, -2};\n \n unordered_map<int, unordered_map<int,int>> dp; \n \n bool isValid(int i, int j) {\n return (i >= 0 && j >= 0 && i <= 49 && j <= 49);\n }\n\n int calcMoves(in... |
3,560 | <p>There is a <code>50 x 50</code> chessboard with <strong>one</strong> knight and some pawns on it. You are given two integers <code>kx</code> and <code>ky</code> where <code>(kx, ky)</code> denotes the position of the knight, and a 2D array <code>positions</code> where <code>positions[i] = [x<sub>i</sub>, y<sub>i</su... | 3 | {
"code": "using Grid = array<array<char, 50>, 50>;\n\nclass Solution {\n vector<vector<short>> memo;\npublic:\n int maxMoves(int kx, int ky, vector<vector<int>>& positions) {\n memo = vector<vector<short>>(1<<positions.size(), vector<short>(positions.size()+1, -1));\n vector<Grid> distances;\n ... |
3,560 | <p>There is a <code>50 x 50</code> chessboard with <strong>one</strong> knight and some pawns on it. You are given two integers <code>kx</code> and <code>ky</code> where <code>(kx, ky)</code> denotes the position of the knight, and a 2D array <code>positions</code> where <code>positions[i] = [x<sub>i</sub>, y<sub>i</su... | 3 | {
"code": "#define ll long long \nclass Solution {\n vector<vector<int>>moves;\n bool issafe(ll x, ll y, ll n, ll m)\n {\n return (((0<=x)&&(x<n))&&((0<=y)&&(y<m)));\n }\n ll calc(ll kx , ll ky , ll px , ll py)\n {\n ll dx[] = {2,1,2,1,-2,-1,-2,-1};\n ll dy[] = {1,2,-1,-2,1,2,-1... |
3,560 | <p>There is a <code>50 x 50</code> chessboard with <strong>one</strong> knight and some pawns on it. You are given two integers <code>kx</code> and <code>ky</code> where <code>(kx, ky)</code> denotes the position of the knight, and a 2D array <code>positions</code> where <code>positions[i] = [x<sub>i</sub>, y<sub>i</su... | 3 | {
"code": "#include <vector>\n#include <queue>\n#include <algorithm>\n#include <cstring>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<pair<int, int>> knightMoves = {{2, 1}, {2, -1}, {-2, 1}, {-2, -1}, {1, 2}, {1, -2}, {-1, 2}, {-1, -2}};\n \n int calculateDistance(int startX, int startY, int e... |
3,560 | <p>There is a <code>50 x 50</code> chessboard with <strong>one</strong> knight and some pawns on it. You are given two integers <code>kx</code> and <code>ky</code> where <code>(kx, ky)</code> denotes the position of the knight, and a 2D array <code>positions</code> where <code>positions[i] = [x<sub>i</sub>, y<sub>i</su... | 3 | {
"code": "class Solution {\npublic:\n vector<pair<int, int>> moves = {{2, 1}, {2, -1}, {-2, 1}, {-2, -1}, {1, 2}, {1, -2}, {-1, 2}, {-1, -2}};\n int dp[16][1 << 16][2]; // 15 positions (knight + max 14 pawns), mask of visited pawns, turn (a)\n\n // BFS to compute minimum moves from (sx, sy) to (ex, ey)\n ... |
3,560 | <p>There is a <code>50 x 50</code> chessboard with <strong>one</strong> knight and some pawns on it. You are given two integers <code>kx</code> and <code>ky</code> where <code>(kx, ky)</code> denotes the position of the knight, and a 2D array <code>positions</code> where <code>positions[i] = [x<sub>i</sub>, y<sub>i</su... | 3 | {
"code": "class Solution {\npublic:\n /*\n we can get distance between all pairs of positions\n represent as N nodes in a graph, fully connected\n \n 2^15 = 30k for reference\n \n base case: there is only 1 pawn\n the knight goes directly to the node\n \n there are 2 pawns (a, b):\n ... |
3,560 | <p>There is a <code>50 x 50</code> chessboard with <strong>one</strong> knight and some pawns on it. You are given two integers <code>kx</code> and <code>ky</code> where <code>(kx, ky)</code> denotes the position of the knight, and a 2D array <code>positions</code> where <code>positions[i] = [x<sub>i</sub>, y<sub>i</su... | 3 | {
"code": "#define ll long long\nclass Solution\n{\npublic:\n\n vector<pair<ll,ll>> m={{1,2},{1,-2},{2,1},{2,-1},{-1,2},{-1,-2},{-2,1},{-2,-1}};\n ll solve(ll cu,map<pair<pair<ll,ll>,ll>,ll> &m2,ll tx,ll x, ll y, ll i, vector<vector<vector<ll>>> &m1 ,vector<vector<int>> &p)\n {\n\n if (i == 0)\n ... |
3,560 | <p>There is a <code>50 x 50</code> chessboard with <strong>one</strong> knight and some pawns on it. You are given two integers <code>kx</code> and <code>ky</code> where <code>(kx, ky)</code> denotes the position of the knight, and a 2D array <code>positions</code> where <code>positions[i] = [x<sub>i</sub>, y<sub>i</su... | 3 | {
"code": "#include <bits/stdc++.h>\n#ifdef DEBUG\n#include \"debug.h\"\n#else\n#define dbg(x...)\n#endif\nusing namespace std;\n\nconst int MM = 55;\nint moves[MM][MM][MM][MM], vis[MM][MM][MM][MM];\n\nclass Solution {\npublic:\n int maxMoves(int kx, int ky, vector<vector<int>>& positions) {\n\t\tint n = positions... |
3,560 | <p>There is a <code>50 x 50</code> chessboard with <strong>one</strong> knight and some pawns on it. You are given two integers <code>kx</code> and <code>ky</code> where <code>(kx, ky)</code> denotes the position of the knight, and a 2D array <code>positions</code> where <code>positions[i] = [x<sub>i</sub>, y<sub>i</su... | 3 | {
"code": "#define ll long long int\n#define vi vector<int>\n#define vvi vector<vi>\n#define vvvi vector<vvi>\n#define ff first\n#define ss second\n#define fr(i, a, b) for (int i = a; i < b; i++)\nclass Solution {\npublic:\nvvi p;\nvvvi d;\n int dy[8] = {-2,-1,1,2,2,1,-1,-2};\n int dx[8] = {1,2,2,1,-1,-2,-2,-1}... |
3,560 | <p>There is a <code>50 x 50</code> chessboard with <strong>one</strong> knight and some pawns on it. You are given two integers <code>kx</code> and <code>ky</code> where <code>(kx, ky)</code> denotes the position of the knight, and a 2D array <code>positions</code> where <code>positions[i] = [x<sub>i</sub>, y<sub>i</su... | 3 | {
"code": "#include <bits/stdc++.h>\nusing namespace std;\n \nint dist[50][50][50][50];\nint dx[8] = {1, 2, 2, 1, -1, -2, -2, -1};\nint dy[8] = {2, 1, -1, -2, -2, -1, 1, 2};\n \nvoid dis(int startx, int starty) {\n queue<pair<pair<int, int>, int>> q;\n q.push({{startx, starty}, 0});\n dist[startx][starty][st... |
3,560 | <p>There is a <code>50 x 50</code> chessboard with <strong>one</strong> knight and some pawns on it. You are given two integers <code>kx</code> and <code>ky</code> where <code>(kx, ky)</code> denotes the position of the knight, and a 2D array <code>positions</code> where <code>positions[i] = [x<sub>i</sub>, y<sub>i</su... | 3 | {
"code": "#include <bits/stdc++.h>\nusing namespace std;\n\nint dist[50][50][50][50]; // 4D array to store distances between all pairs of points on the board\nint dx[8] = {1, 2, 2, 1, -1, -2, -2, -1}; // Possible moves in x-direction for a knight\nint dy[8] = {2, 1, -1, -2, -2, -1, 1, 2}; // Possible moves in y-dire... |
3,560 | <p>There is a <code>50 x 50</code> chessboard with <strong>one</strong> knight and some pawns on it. You are given two integers <code>kx</code> and <code>ky</code> where <code>(kx, ky)</code> denotes the position of the knight, and a 2D array <code>positions</code> where <code>positions[i] = [x<sub>i</sub>, y<sub>i</su... | 3 | {
"code": "class Solution {\npublic:\n int dpArr[16][2][(1 << 16)];\n \n int maxMoves(int kx, int ky, vector<vector<int>>& positions) {\n positions.push_back(vector<int> {kx, ky});\n vector<vector<int>> shortestDist;\n for (int i = 0; i < positions.size(); i++){\n shortestDist... |
3,560 | <p>There is a <code>50 x 50</code> chessboard with <strong>one</strong> knight and some pawns on it. You are given two integers <code>kx</code> and <code>ky</code> where <code>(kx, ky)</code> denotes the position of the knight, and a 2D array <code>positions</code> where <code>positions[i] = [x<sub>i</sub>, y<sub>i</su... | 3 | {
"code": "#define ll long long\n#define pb push_back\nclass Solution {\npublic:\n vector<vector<ll>>f(ll xnode,ll ynode,ll delx[],ll dely[]){\n vector<vector<ll>>dist(50,vector<ll>(50,1e15));\n dist[xnode][ynode]=0;\n\n\n // priority_queue<vector<ll>,vector<vector<ll>>,greater<vector<ll>>>pq;... |
3,560 | <p>There is a <code>50 x 50</code> chessboard with <strong>one</strong> knight and some pawns on it. You are given two integers <code>kx</code> and <code>ky</code> where <code>(kx, ky)</code> denotes the position of the knight, and a 2D array <code>positions</code> where <code>positions[i] = [x<sub>i</sub>, y<sub>i</su... | 3 | {
"code": " int dp[16][(1<<16)];\n int minDistances[16][16]; // if ith index is my current position index and target pos is y \nclass Solution {\npublic:\n void setMinDistances(vector<vector<int>>& pos)\n {\n int n = pos.size();\n for(int i=0;i<n;i++)\n {\n for(int j=0;j<n;... |
3,560 | <p>There is a <code>50 x 50</code> chessboard with <strong>one</strong> knight and some pawns on it. You are given two integers <code>kx</code> and <code>ky</code> where <code>(kx, ky)</code> denotes the position of the knight, and a 2D array <code>positions</code> where <code>positions[i] = [x<sub>i</sub>, y<sub>i</su... | 3 | {
"code": "class Solution {\n public:\n int maxMoves(int kx, int ky, vector<vector<int>>& positions) {\n // dist[i][j][x][y] := the distance from (i, j) to (x, y)\n static int dist[kSize][kSize][kSize][kSize];\n\n positions.push_back({kx, ky});\n for (const vector<int>& position : positions)\n bfs(/... |
3,560 | <p>There is a <code>50 x 50</code> chessboard with <strong>one</strong> knight and some pawns on it. You are given two integers <code>kx</code> and <code>ky</code> where <code>(kx, ky)</code> denotes the position of the knight, and a 2D array <code>positions</code> where <code>positions[i] = [x<sub>i</sub>, y<sub>i</su... | 3 | {
"code": "class Solution {\npublic:\n int dir[8][2] = {{2,1}, {1,2}, {-2,1}, {-1,2}, {1,-2}, {2,-1}, {-1,-2}, {-2,-1}};\n vector<vector<int>> dis;\n int n = 50, m;\n unordered_map<int, unordered_map<int, int>> dp;\n\n int bfs(int r, int c, int er, int ec) {\n vector<vector<int>> vis(n, vector<i... |
3,560 | <p>There is a <code>50 x 50</code> chessboard with <strong>one</strong> knight and some pawns on it. You are given two integers <code>kx</code> and <code>ky</code> where <code>(kx, ky)</code> denotes the position of the knight, and a 2D array <code>positions</code> where <code>positions[i] = [x<sub>i</sub>, y<sub>i</su... | 3 | {
"code": "class Solution {\npublic:\n int dir[8][2] = {{2,1}, {1,2}, {-2,1}, {-1,2}, {1,-2}, {2,-1}, {-1,-2}, {-2,-1}};\n vector<vector<int>> dis;\n int n = 50, m;\n unordered_map<int, unordered_map<int, int>> dp;\n\n int bfs(int r, int c, int er, int ec) {\n vector<vector<int>> vis(n, vector<i... |
3,560 | <p>There is a <code>50 x 50</code> chessboard with <strong>one</strong> knight and some pawns on it. You are given two integers <code>kx</code> and <code>ky</code> where <code>(kx, ky)</code> denotes the position of the knight, and a 2D array <code>positions</code> where <code>positions[i] = [x<sub>i</sub>, y<sub>i</su... | 3 | {
"code": "class Solution {\n int dp[16][80000][2];\n int dx[8]={-2,-1,1,2,2,1,-1,-2};\n int dy[8]={1,2,2,1,-1,-2,-2,-1};\n int countMoves(int i1,int j1,int i2,int j2){\n queue<vector<int>> q;\n vector<vector<int>> vis(50,vector<int>(50,0));\n vis[i1][j1]=1;\n q.pus... |
3,560 | <p>There is a <code>50 x 50</code> chessboard with <strong>one</strong> knight and some pawns on it. You are given two integers <code>kx</code> and <code>ky</code> where <code>(kx, ky)</code> denotes the position of the knight, and a 2D array <code>positions</code> where <code>positions[i] = [x<sub>i</sub>, y<sub>i</su... | 3 | {
"code": "class Solution {\npublic:\nint dx[8]={2,2,-2,-2,1,1,-1,-1};\nint dy[8]={1,-1,1,-1,2,-2,2,-2};\n \n void helper(int p1,int q1,map<vector<int>,int>&m,vector<vector<int>>&temp,int size)\n {\n int start=m[{p1,q1}];\n vector<vector<bool>>vis(50,vector<bool>(50,false));\n // temp[sta... |
3,560 | <p>There is a <code>50 x 50</code> chessboard with <strong>one</strong> knight and some pawns on it. You are given two integers <code>kx</code> and <code>ky</code> where <code>(kx, ky)</code> denotes the position of the knight, and a 2D array <code>positions</code> where <code>positions[i] = [x<sub>i</sub>, y<sub>i</su... | 3 | {
"code": "class Solution {\npublic:\n // int dp3[51][51] = {0};\n int getsteps(int x, int y, \n int tx, int ty, vector<vector<int>> &dp3) \n{ \n // if knight is on the target \n // position return 0. \n if (x == tx && y == ty) \n return dp3[0][0]; \n else { \n \n ... |
3,560 | <p>There is a <code>50 x 50</code> chessboard with <strong>one</strong> knight and some pawns on it. You are given two integers <code>kx</code> and <code>ky</code> where <code>(kx, ky)</code> denotes the position of the knight, and a 2D array <code>positions</code> where <code>positions[i] = [x<sub>i</sub>, y<sub>i</su... | 3 | {
"code": "class Solution {\npublic:\n int dp[16][1 << 15][2];\n int dr[8] = {-2, -1, 1, 2, 2, 1, -1, -2};\n int dc[8] = {1, 2, 2, 1, -1, -2, -2, -1};\n int dist[16][16];\n\n void bfs(int id, int sr, int sc, int e_id, int er, int ec) {\n vector<vector<int>> vis(50, vector<int>(50, 0));\n ... |
3,560 | <p>There is a <code>50 x 50</code> chessboard with <strong>one</strong> knight and some pawns on it. You are given two integers <code>kx</code> and <code>ky</code> where <code>(kx, ky)</code> denotes the position of the knight, and a 2D array <code>positions</code> where <code>positions[i] = [x<sub>i</sub>, y<sub>i</su... | 3 | {
"code": "int minMoves[50][50][50][50];\nint counter=0;\nclass Solution {\npublic:\n\n int arx[8]={1,-1,2,-2,1,-1,2,-2};\n int ary[8]={2,2,1,1,-2,-2,-1,-1};\n\n\n int solve(int lastTakenIndex,int bitMask,int flag,vector<vector<int>>&pos,vector<vector<vector<int>>>&dp,int maxBit){\n if(bitMask==maxBit... |
3,560 | <p>There is a <code>50 x 50</code> chessboard with <strong>one</strong> knight and some pawns on it. You are given two integers <code>kx</code> and <code>ky</code> where <code>(kx, ky)</code> denotes the position of the knight, and a 2D array <code>positions</code> where <code>positions[i] = [x<sub>i</sub>, y<sub>i</su... | 3 | {
"code": "int minMove[50][50][50][50];\nint counter=0;\nclass Solution {\npublic:\n \n int X[8] = { 2, 1, -1, -2, -2, -1, 1, 2 };\n int Y[8] = { 1, 2, 2, 1, -1, -2, -2, -1 };\n\n int f(int lastTakenIndex,int bitMask,int flg,vector<vector<int>>& Positions,int mxBitMaskSize, vector<vector<vector<int>>>&dp)\n ... |
3,560 | <p>There is a <code>50 x 50</code> chessboard with <strong>one</strong> knight and some pawns on it. You are given two integers <code>kx</code> and <code>ky</code> where <code>(kx, ky)</code> denotes the position of the knight, and a 2D array <code>positions</code> where <code>positions[i] = [x<sub>i</sub>, y<sub>i</su... | 3 | {
"code": "#include <vector>\n#include <queue>\n#include <algorithm>\n#include <cstring>\n\nclass Solution {\nprivate:\n static const int KNIGHT_MOVES[8][2];\n\n int dp[50][1 << 16];\n int distances[17][17];\n int pawnCount;\n\n void calculateDistances(int startX, int startY, const std::vector<std::vec... |
3,560 | <p>There is a <code>50 x 50</code> chessboard with <strong>one</strong> knight and some pawns on it. You are given two integers <code>kx</code> and <code>ky</code> where <code>(kx, ky)</code> denotes the position of the knight, and a 2D array <code>positions</code> where <code>positions[i] = [x<sub>i</sub>, y<sub>i</su... | 3 | {
"code": "class Solution {\nprivate:\n static const int KNIGHT_MOVES[8][2];\n\n int dp[50][1 << 16];\n int distances[17][17];\n int pawnCount;\n\n void calculateDistances(int startX, int startY, const std::vector<std::vector<int>>& pawns) {\n for (int i = 0; i < pawnCount; ++i) {\n d... |
3,582 | <p>There are <code>n</code> mountains in a row, and each mountain has a height. You are given an integer array <code>height</code> where <code>height[i]</code> represents the height of mountain <code>i</code>, and an integer <code>threshold</code>.</p>
<p>A mountain is called <strong>stable</strong> if the mountain ju... | 0 | {
"code": "class Solution {\npublic:\n vector<int> stableMountains(vector<int>& height, int threshold) {\n vector<int> ret;\n for(int i=0;i<height.size()-1;i++)\n {\n if(height[i]>threshold)\n ret.push_back(i+1);\n }\n return ret;\n }\n};",
"memory": "2... |
3,582 | <p>There are <code>n</code> mountains in a row, and each mountain has a height. You are given an integer array <code>height</code> where <code>height[i]</code> represents the height of mountain <code>i</code>, and an integer <code>threshold</code>.</p>
<p>A mountain is called <strong>stable</strong> if the mountain ju... | 0 | {
"code": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> stableMountains(vector<int>& height, int threshold) {\n vector<int> result;\n for (int i = 0; i < height.size() - 1; i++) {\n if (height[i] > threshold) {\n result.push_back(i+1);\n... |
3,582 | <p>There are <code>n</code> mountains in a row, and each mountain has a height. You are given an integer array <code>height</code> where <code>height[i]</code> represents the height of mountain <code>i</code>, and an integer <code>threshold</code>.</p>
<p>A mountain is called <strong>stable</strong> if the mountain ju... | 0 | {
"code": "class Solution {\npublic:\n vector<int> stableMountains(vector<int>& height, int threshold) {\n vector<int> result;\n result.reserve(height.size());\n for (int i = 0; i < height.size() - 1; ++i)\n if (height[i] > threshold)\n result.push_back(i + 1);\n ... |
3,582 | <p>There are <code>n</code> mountains in a row, and each mountain has a height. You are given an integer array <code>height</code> where <code>height[i]</code> represents the height of mountain <code>i</code>, and an integer <code>threshold</code>.</p>
<p>A mountain is called <strong>stable</strong> if the mountain ju... | 0 | {
"code": "class Solution {\npublic:\n std::vector<int> stableMountains(std::vector<int>& height, int threshold) {\n std::vector<int> result;\n for (int i = 1; i < height.size(); ++i) {\n if (height[i] && height[i - 1] > threshold) {\n result.push_back(i);\n }\n ... |
3,582 | <p>There are <code>n</code> mountains in a row, and each mountain has a height. You are given an integer array <code>height</code> where <code>height[i]</code> represents the height of mountain <code>i</code>, and an integer <code>threshold</code>.</p>
<p>A mountain is called <strong>stable</strong> if the mountain ju... | 0 | {
"code": "class Solution {\npublic:\n vector<int> stableMountains(vector<int>& height, int threshold) {\n vector<int> stable;\n for (int i = 1; i < height.size(); i++) {\n if (height[i - 1] > threshold) {\n stable.push_back(i);\n }\n }\n return stab... |
3,558 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p>
<p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p>
<p>You can move up, down, left, or right from one cell to another ad... | 0 | {
"code": "class Solution {\npublic:\n int dp[60][60];\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n const int m = grid.size();\n const int n = grid[0].size();\n for (int i = 0; i < m; ++i) {\n for (int j = 0; j < n; ++j) {\n dp[i][j] = (int)(1e9);... |
3,558 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p>
<p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p>
<p>You can move up, down, left, or right from one cell to another ad... | 0 | {
"code": "#pragma GCC optimize(\"O3,unroll-loops\")\n#pragma GCC target(\"avx2,bmi,bmi2,lzcnt,popcnt\")\n\nstatic const bool __boost = []() {\n cin.tie(nullptr);\n cout.tie(nullptr);\n return std::ios_base::sync_with_stdio(false);\n }();\n\n\nconst size_t BUFFER_SIZE = 0x6fafffff;\nalignas(std::max_align... |
3,558 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p>
<p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p>
<p>You can move up, down, left, or right from one cell to another ad... | 0 | {
"code": "class Solution {\npublic:\n int m, n;\n int dp[51][51][101];\n bool solve(int i, int j, vector<vector<int>> &grid, int health){\n if(i==m-1 && j==n-1){\n return (health - grid[i][j] >= 1);\n }\n if(i<0 || j<0 || i>=m || j>=n || grid[i][j] == 2) return false;\n ... |
3,558 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p>
<p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p>
<p>You can move up, down, left, or right from one cell to another ad... | 0 | {
"code": "class Solution {\n int memo[51][51][101];\n bool solve(int i,int j,vector<vector<int>>& grid, int& health){\n if(i<0 || j<0 || i>=grid.size() || j>= grid[0].size() || grid[i][j]==-1 || health<0)return false;\n if(i == grid.size()-1 && j == grid[0].size()-1){\n if(grid[i][j] =... |
3,558 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p>
<p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p>
<p>You can move up, down, left, or right from one cell to another ad... | 0 | {
"code": "class Solution {\npublic:\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n priority_queue<pair<int,pair<int,int>>> pq;\n int mat[51][51]={0};\n int m=grid.size();\n int n=grid[0].size();\n pq.push({health-grid[0][0],{0,0}});\n mat[0][0]=health-1;\n... |
3,558 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p>
<p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p>
<p>You can move up, down, left, or right from one cell to another ad... | 0 | {
"code": "int dir[4][2] = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}};\nclass node\n{\npublic:\n node(int a, int b, int c)\n {\n x = a;\n y = b;\n val = c;\n }\n int x, y, val;\n bool operator<(const node& n) const\n {\n return val > n.val;\n } \n};\nclass Solution {\npublic:... |
3,558 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p>
<p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p>
<p>You can move up, down, left, or right from one cell to another ad... | 1 | {
"code": "class Solution {\npublic:\n bool findSafeWalk(vector<vector<int>>& g, int h) {\n int m = g.size(), n = g[0].size();\n vector<vector<int>> d(m, vector<int>(n, -1));\n queue<pair<int, int>> q;\n q.push({0, 0});\n d[0][0] = h - g[0][0];\n\n vector<int> dirs = {0, 1... |
3,558 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p>
<p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p>
<p>You can move up, down, left, or right from one cell to another ad... | 1 | {
"code": "class Solution {\npublic:\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n vector<vector<int>> dir = {{1, 0}, {0, 1}, {0, -1}, {-1, 0}};\n int m = grid.size();\n int n = grid[0].size();\n \n // Store the maximum health at each cell\n vector<vector<... |
3,558 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p>
<p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p>
<p>You can move up, down, left, or right from one cell to another ad... | 1 | {
"code": "class Solution {\npublic:\n int hx[4] = {1, 0, -1, 0};\n int hy[4] = {0, 1, 0, -1};\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n int m = (int)grid.size(), n = (int)grid[0].size();\n deque <pair <int, int> > q;\n #define mp make_pair\n q.push_back(mp(0,... |
3,558 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p>
<p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p>
<p>You can move up, down, left, or right from one cell to another ad... | 1 | {
"code": "class Solution \n{\nprivate:\n int m,n;\n\n bool findSafeWalkUtil(vector<vector<int>>& grid,int h)\n {\n //we can also apply dijkstra's algorithm directly, applying 0-1 BFS algorithm \n vector<vector<int>> dist(m,vector<int>(n,INT_MAX));\n dist[0][0]=grid[0][0];\n\n // ... |
3,558 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p>
<p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p>
<p>You can move up, down, left, or right from one cell to another ad... | 1 | {
"code": "class Solution {\npublic:\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n auto m = grid.size();\n auto n = grid[0].size();\n auto hh = std::vector<std::vector<int>>(m, std::vector<int>(n));\n auto visited = std::vector<std::vector<bool>>(m, std::vector<bool>(n)... |
3,558 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p>
<p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p>
<p>You can move up, down, left, or right from one cell to another ad... | 1 | {
"code": "class Solution {\npublic:\n \n void checkNeightbor(int n, int m, vector<vector<int>>& grid, vector<vector<int>>& path, int x, int y, \n queue <pair<int, int>> &qToProcess, queue <pair<int, int>> &qToProcessNext) {\n if (x<0 || x>=n) return;\n if (y<0 || y>=m) retur... |
3,558 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p>
<p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p>
<p>You can move up, down, left, or right from one cell to another ad... | 1 | {
"code": "#include <bits/stdc++.h>\nusing namespace std;\n\n\ntypedef long long int ll;\nclass Solution {\npublic:\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n \n ll m = grid.size();ll n = grid[0].size();\n cout<<m<<\" \"<<n<<\"\\n\";\n vector<vector<ll>> g(m+5,vector... |
3,558 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p>
<p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p>
<p>You can move up, down, left, or right from one cell to another ad... | 1 | {
"code": "#include <bits/stdc++.h>\nusing namespace std;\n\n\ntypedef long long int ll;\nclass Solution {\npublic:\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n \n ll m = grid.size();ll n = grid[0].size();\n cout<<m<<\" \"<<n<<\"\\n\";\n vector<vector<ll>> g(m+5,vector... |
3,558 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p>
<p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p>
<p>You can move up, down, left, or right from one cell to another ad... | 2 | {
"code": "class Solution {\nprivate:\n int bfs(int p, int q, vector<vector<int>>& grid, vector<vector<int>>& vis,\n queue<pair<pair<int, int>, int>>& qq, int health) {\n int n = grid.size();\n int m = grid[0].size();\n qq.push({{p, q}, health - grid[p][q]});\n vis[p][q] = he... |
3,558 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p>
<p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p>
<p>You can move up, down, left, or right from one cell to another ad... | 2 | {
"code": "class Solution {\npublic:\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n int n = grid.size();\n int m = grid[0].size();\n int dr[4] = {1, 0, -1, 0};\n int dc[4] = {0, -1, 0, 1}; \n queue<pair<int, pair<int, int>>>q;\n q.push({health-grid[0][0], {... |
3,558 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p>
<p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p>
<p>You can move up, down, left, or right from one cell to another ad... | 2 | {
"code": "class Solution {\npublic:\n bool findSafeWalk(vector<vector<int>>& g, int health) {\n int m = g.size(), n = g[0].size(), cnt[51][51] = {};\n memset(cnt, 0x3f, sizeof(cnt));\n deque<array<int,2>> dq;\n dq.push_front({0, 0});\n cnt[0][0] = g[0][0];\n while (!dq.em... |
3,558 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p>
<p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p>
<p>You can move up, down, left, or right from one cell to another ad... | 2 | {
"code": "class Solution {\npublic:\n // bool isPossible(vector<vector<int>>& grid, int health,int row,int col){\n // if(health<=0){\n // return false;\n // }\n // if(row==grid.size()-1 && col==grid[0].size()-1){\n // return 1;\n // }\n // int ans=0;\n /... |
3,558 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p>
<p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p>
<p>You can move up, down, left, or right from one cell to another ad... | 2 | {
"code": "class Solution {\npublic:\n int r[4]={0,-1,0,1};\n int c[4]={-1, 0, 1, 0};\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n vector<vector<int>> vis(grid.size(), vector<int>(grid[0].size(), 0));\n priority_queue<vector<int>> pq;\n if(grid[0][0]... |
3,558 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p>
<p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p>
<p>You can move up, down, left, or right from one cell to another ad... | 2 | {
"code": "class Solution {\npublic:\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n int n = grid.size(), m = grid[0].size();\n vector<vector<int>> dist(n, vector<int>(m, 1e2));\n vector<vector<int>> vis(n, vector<int>(m, 0));\n set<pair<int, pair<int,int>>> st;\n\n ... |
3,558 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p>
<p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p>
<p>You can move up, down, left, or right from one cell to another ad... | 2 | {
"code": "class Solution {\npublic:\n bool findSafeWalk(vector<vector<int>>& grid, int h) \n {\n set<pair<int,pair<int,int>>> st;\n st.insert({h*-1 + grid[0][0],{0,0}});\n int n = grid[0].size();\n int m = grid.size();\n\n vector<vector<int>> dis(m,vector<int> (n));\n\n ... |
3,558 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p>
<p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p>
<p>You can move up, down, left, or right from one cell to another ad... | 2 | {
"code": "class Solution {\npublic:\n bool findSafeWalk(vector<vector<int>>& gg, int health) {\n const int m = gg.size();\n const int n = gg[0].size();\n\n vector<vector<int>> dd(m, vector<int>(n, -1));\n map<int, set<pair<int, int>>> mp;\n dd[0][0] = gg[0][0];\n mp[gg[0]... |
3,558 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p>
<p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p>
<p>You can move up, down, left, or right from one cell to another ad... | 2 | {
"code": "class Solution {\npublic:\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n int m = grid.size(), n = grid[0].size();\n vector<vector<bool>> visited(m, vector<bool>(n, false));\n vector<int> dir = {0, 1, 0, -1, 0};\n priority_queue<vector<int>, vector<vector<int>>... |
3,558 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p>
<p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p>
<p>You can move up, down, left, or right from one cell to another ad... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<int>>arr;\n int h;\n vector<vector<int>>dp;\n \n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n arr = grid;\n h = health;\n int n= grid.size();\n int m= grid[0].size();\n dp.resize(n, vector<int>(... |
3,558 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p>
<p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p>
<p>You can move up, down, left, or right from one cell to another ad... | 2 | {
"code": "class Solution {\n bool f=false;\n void dfs(int n, int m, int h, vector<vector<int>>&g, vector<vector<bool>> &vis, vector<vector<vector<bool>>> &dp){\n dp[n][m][h]=true;\n if (g[n][m])\n h--;\n if (h<1)\n return;\n vis[n][m]=true;\n if ((n==g.... |
3,558 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p>
<p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p>
<p>You can move up, down, left, or right from one cell to another ad... | 2 | {
"code": "class Solution {\npublic:\n bool IsOutOfBound(int &i, int &j, int &n, int &m) {\n return (i<0 || j<0 || i==n || j==m);\n }\n \n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n priority_queue<vector<int>> pq;\n int n=grid.size(), m=grid[0].size();\n \n ... |
3,558 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p>
<p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p>
<p>You can move up, down, left, or right from one cell to another ad... | 2 | {
"code": "class Solution {\npublic:\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n int n=grid.size(),m=grid[0].size();\n vector<vector<int>> dis(n,vector<int>(m,1e9));\n queue<pair<int,pair<int,int>>> q;\n q.push({grid[0][0],{0,0}});\n while(!q.empty())\n ... |
3,558 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p>
<p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p>
<p>You can move up, down, left, or right from one cell to another ad... | 2 | {
"code": "class Solution {\npublic:\n#define ll long long\n#define pb push_back\n#define ff first\n#define ss second\n#define mp make_pair\n#define lb lower_bound\n#define ub upper_bound\n#define all(v) (v).begin(),(v).end()\n#define endl \"\\n\"\n\n bool findSafeWalk(vector<vector<int>>& g, int h) {\n ll... |
3,558 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p>
<p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p>
<p>You can move up, down, left, or right from one cell to another ad... | 2 | {
"code": "using ll = long long;\nusing pll = pair<ll, ll>;\ntemplate <class T>\nusing vec = vector<T>;\n\n#define FOR(i, s, e) for (ll i = (ll)s; i < (ll)e; i++)\n#define CFOR(i, s, e) for (ll i = (ll)s; i <= (ll)e; i++)\n#define TRAV(a, c) for (const auto &a : c)\n#define dbg(x) cerr << \"ln\" << __LINE__ << \": \"... |
3,558 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p>
<p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p>
<p>You can move up, down, left, or right from one cell to another ad... | 2 | {
"code": "class Solution {\npublic:\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n int n=grid.size();\n int m=grid[0].size();\n set<pair<int,int>>visit;\n multiset<pair<int,pair<int,int>>>st;\n if(grid[0][0])\n st.insert({1,{0,0}});\n else st.insert... |
3,558 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p>
<p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p>
<p>You can move up, down, left, or right from one cell to another ad... | 2 | {
"code": "class Solution {\npublic:\n\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n int row=grid.size();\n int col=grid[0].size();\n if(row==1 && col==1)\n {\n if(health>grid[0][0])\n {\n return 1;\n }\n else\n... |
3,558 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p>
<p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p>
<p>You can move up, down, left, or right from one cell to another ad... | 2 | {
"code": "using ii=pair<int,int>;\nclass Solution {\npublic:\n vector<int> dx={0,1,0,-1};\n vector<int> dy={1,0,-1,0};\n vector<vector<int>> dist,vis;\n int n,m;\n bool check(int x,int y){\n if(x>=0 && x<n && y>=0 && y<m) return true;\n return false;\n }\n vector<ii> cal(int row,in... |
3,558 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p>
<p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p>
<p>You can move up, down, left, or right from one cell to another ad... | 2 | {
"code": "class Solution {\npublic:\n\nvector<int> dx ={-1,1,0,0};\nvector<int> dy={0,0,1,-1};\nbool check(int x,int y,int h,int w){\n // check if grid is blocked or path\n return x>=0 and x<h and y>=0 and y<w;\n}\nint convert(int x,int y,int cols){\n return cols*x+y;\n}\npair<int,int> convertback(int xy,... |
3,558 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p>
<p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p>
<p>You can move up, down, left, or right from one cell to another ad... | 2 | {
"code": "class Solution {\npublic:\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n int n=grid.size(),m=grid[0].size();\n if(grid[0][0]==1) health--;\n if(health<1) return false;\n queue<pair<int,pair<int,int>>> q;\n q.push({0,{0,health}});\n map<pair<int,i... |
3,558 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p>
<p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p>
<p>You can move up, down, left, or right from one cell to another ad... | 2 | {
"code": "class Solution {\npublic:\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n int m = grid.size(), n = grid[0].size();\n vector<vector<vector<pair<int, int>>>> g(m, vector<vector<pair<int, int>>>(n));\n vector<int> dir = {0, -1, 0, 1, 0};\n priority_queue<tuple<int... |
3,558 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p>
<p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p>
<p>You can move up, down, left, or right from one cell to another ad... | 3 | {
"code": "class Solution {\npublic:\n bool canReachEnd(vector<vector<int>>& grid, int health, int r, int c, vector<vector<vector<bool>>>& memo, vector<vector<vector<bool>>>& visited) {\n if (r == grid.size() - 1 && c == grid[0].size() - 1) {\n if (grid[r][c] == 1) {\n health -= 1;... |
3,558 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p>
<p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p>
<p>You can move up, down, left, or right from one cell to another ad... | 3 | {
"code": "class Compare{\n public:\n bool operator()(vector<int8_t>&a,vector<int8_t>&b)\n {\n return a[0]<b[0];\n }\n};\nclass Solution {\npublic:\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n int8_t n = grid.size();\n int8_t m = grid[0].size();\n vector<ve... |
3,558 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p>
<p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p>
<p>You can move up, down, left, or right from one cell to another ad... | 3 | {
"code": "class Solution {\npublic:\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n int m = grid.size();\n int n = grid[0].size();\n \n vector<vector<int>> dp(m, vector<int>(n, 0));\n dp[0][0] = health - grid[0][0];;\n vector<vector<int>> moves = {{-1,0},{0... |
3,558 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p>
<p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p>
<p>You can move up, down, left, or right from one cell to another ad... | 3 | {
"code": "class Solution {\npublic:\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n int m = grid.size();\n int n = grid[0].size();\n \n vector<vector<int>> directions = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};\n vector<vector<int>> visited(m, vector<int>(n, -1));\n ... |
3,558 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p>
<p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p>
<p>You can move up, down, left, or right from one cell to another ad... | 3 | {
"code": "class Solution {\npublic:\n bool safe(int i, int j, int m, int n, vector<vector<int>>& visited) {\n if(i<0 || j<0 || i>=m || j>= n || visited[i][j] == 1) return false;\n return true;\n }\n bool walk(int x, int y, vector<vector<int>>& grid, int health, int m, int n, \n vector<vect... |
3,558 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p>
<p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p>
<p>You can move up, down, left, or right from one cell to another ad... | 3 | {
"code": "class Solution {\npublic:\n bool safe(int i, int j, int m, int n, vector<vector<int>>& visited) {\n if(i<0 || j<0 || i>=m || j>= n || visited[i][j] == 1) return false;\n return true;\n }\n bool walk(int x, int y, vector<vector<int>>& grid, int health, int m, int n, \n vector<vecto... |
3,558 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p>
<p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p>
<p>You can move up, down, left, or right from one cell to another ad... | 3 | {
"code": "class Solution {\npublic:\n int row, col;\n vector<vector<int>> direction = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};\n\n bool isSafe(int i, int j) {\n return (i >= 0 && i < row && j >= 0 && j < col);\n }\n\n vector<vector<vector<int>>> dp;\n vector<vector<int>> visited;\n\n bool solv... |
3,558 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p>
<p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p>
<p>You can move up, down, left, or right from one cell to another ad... | 3 | {
"code": "class Solution {\n vector<int> dr = {0, 1, 0, -1};\n vector<int> dc = {1, 0, -1, 0};\nprivate:\n int solve(int row, int col, int health, vector<vector<int>>& grid, vector<vector<vector<int>>>& memo, vector<vector<bool>>& visited) {\n int m = grid.size();\n int n = grid[0].size();\n ... |
3,558 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p>
<p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p>
<p>You can move up, down, left, or right from one cell to another ad... | 3 | {
"code": "class Solution {\npublic:\n int n,m;\n bool solve(int r, int c, int &health, vector<vector<int>>&grid, vector<vector<int>>&vis,vector<vector<vector<int>>>&dp){\n // health is by reference\n if(r>=n || r<0 || c>=m || c<0 || vis[r][c] || health<=0) return false;\n\n if(dp[r][c][hea... |
3,558 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p>
<p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p>
<p>You can move up, down, left, or right from one cell to another ad... | 3 | {
"code": "class Solution {\npublic:\n\n bool dfs(int i, int j, vector<vector<int>>& grid, int currHealth, vector<vector<vector<short>>>& dp) {\n\n // cout << \"i: \" << i << \" j: \" << j << '\\n';\n\n int m = grid.size(), n = grid[0].size();\n\n if (dp[i][j][currHealth] != -1) {\n ... |
3,558 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p>
<p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p>
<p>You can move up, down, left, or right from one cell to another ad... | 3 | {
"code": "class Solution {\npublic:\n bool inbounds (int x, int y, int n, int m){\n if (x >= 0 && y >= 0 && x < n && y < m) return true;\n return false;\n }\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n int n = grid.size(), m = grid[0].size();\n vector<vector<int... |
3,558 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p>
<p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p>
<p>You can move up, down, left, or right from one cell to another ad... | 3 | {
"code": "class Solution {\npublic:\n bool inbounds (int x, int y, int n, int m){\n if (x >= 0 && y >= 0 && x < n && y < m) return true;\n return false;\n }\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n int n = grid.size(), m = grid[0].size();\n vector<vector<int... |
3,558 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p>
<p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p>
<p>You can move up, down, left, or right from one cell to another ad... | 3 | {
"code": "class Solution {\npublic:\n vector<int> DIRS = {0, 1, 0, -1, 0};\n int DIRS_N = 4;\n\n bool dfs(int i, int j, int h, vector<vector<int>> &grid, vector<vector<bool>> &vis, int n, int m, vector<vector<vector<int>>> &dp) { \n if(h == 0) {\n return dp[i][j][h] = false;\n }... |
3,558 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p>
<p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p>
<p>You can move up, down, left, or right from one cell to another ad... | 3 | {
"code": "class Solution {\npublic:\n vector<int> DIRS = {0, 1, 0, -1, 0};\n int DIRS_N = 4;\n\n bool dfs(int i, int j, int h, vector<vector<int>> &grid, vector<vector<bool>> &vis, int n, int m, vector<vector<vector<int>>> &dp) { \n if(h == 0) {\n return dp[i][j][h] = false;\n }... |
3,558 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p>
<p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p>
<p>You can move up, down, left, or right from one cell to another ad... | 3 | {
"code": "class Solution {\n //bool safe(int)\n vector<vector<int>> dir={{1,0},{0,1},{-1,0},{0,-1}};\n map<pair<int,pair<int,int>>,bool> um;\n bool recur(vector<vector<int>>& grid, int health,int i,int j){\n int m=grid.size(),n=grid[0].size();\n if(health<=0) return 0;\n if(i==m-1 &&... |
3,558 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p>
<p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p>
<p>You can move up, down, left, or right from one cell to another ad... | 3 | {
"code": "class Solution {\npublic:\n bool dfs(vector<vector<int>>& grid, vector<vector<int>>& v, int x, int y, int health) {\n int m = grid.size(), n = grid[0].size();\n\n \n if (health <= 0) return false;\n\n if (x == m - 1 && y == n - 1) return health > 0;\n\n v[x][y] = health;\n\... |
3,558 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p>
<p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p>
<p>You can move up, down, left, or right from one cell to another ad... | 3 | {
"code": "class Solution {\npublic:\nvector<int> r={-1,0,1,0};\nvector<int> c={0,1,0,-1};\nvector<vector<vector<int>>> mem;\nbool solve(vector<vector<int>>& grid, int health,int n,int m,int i, int j,vector<vector<int>>&visited){\n if(i==n-1 && j==m-1){\n return grid[i][j]==1 && health==1? false:true;\n ... |
3,558 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p>
<p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p>
<p>You can move up, down, left, or right from one cell to another ad... | 3 | {
"code": "class Solution {\npublic:\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n int H = grid.size();\n int W = grid[0].size();\n \n queue<tuple<int, int, int>> q; // (row, column, health)\n q.emplace(0, 0, health + (grid[0][0] == 0 ? 0 : -1));\n \n ... |
3,558 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p>
<p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p>
<p>You can move up, down, left, or right from one cell to another ad... | 3 | {
"code": "class Solution {\npublic:\n bool dfs(vector<vector<int>>& grid, int row, int col, int health,\n vector<vector<int>>& visited) {\n int m = grid.size();\n int n = grid[0].size();\n\n if (row < 0 || row >= m || col < 0 || col >= n || health <= 0) {\n return false... |
3,558 | <p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p>
<p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p>
<p>You can move up, down, left, or right from one cell to another ad... | 3 | {
"code": "class Solution {\npublic:\n // 0 1 0 0 0\n // 0 1 0 1 0\n // 0 0 0 1 0\n vector<int> nRow = {-1, 0, 1, 0};\n vector<int> nCol = {0, -1, 0, 1};\n\n bool solve(int row, int col, int n, int m, vector<vector<int>> &grid, int health, map<pair<int, int>, int> &pathVisit, vector<vector<vector<in... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.