For finding the minimum distance you can use indexes of the pawns array in a 2D matrix of size N*N, where distance[i][j] represents shortest distance to reach from pawn at index i to pawn at index j(where N is the size of pawns array,) and for every index you calculate the shortest distance to every other cell which can be done in 50*50 for a single Pawn and for N pawns it boils down to 50*50*N (here N
Last taken is position of 22:22 knight❤
I was very close, coded out bitmask dp all the way. Got WA tho :(
Thankyou for this
Happens. The best thing is that you tried to upsolve and hopefully will get 1 step closer next time :)
please do video for q.2 and q.3 also
For finding the minimum distance you can use indexes of the pawns array in a 2D matrix of size N*N, where distance[i][j] represents shortest distance to reach from pawn at index i to pawn at index j(where N is the size of pawns array,) and for every index you calculate the shortest distance to every other cell which can be done in 50*50 for a single Pawn and for N pawns it boils down to 50*50*N (here N
Good point. I didn't notice this because all pair version passed.
Sir whats wrong with my approach struggling since morning class Solution {
public:
vector dx = {-2, -2, -1, -1, 1, 1, 2, 2};
vector dy = {-1, 1, -2, 2, -2, 2, -1, 1};
int helper(int kx, int ky, pair pyaada, vector& visited, vector& dp) {
if (kx == pyaada.first && ky == pyaada.second) {
return 0;
}
if (kx < 0 || kx >= 50 || ky < 0 || ky >= 50) return 1e9;
if (dp[kx][ky] != -1) return dp[kx][ky];
int mini = 1e9;
if (visited[kx][ky] == 1) return 1e9;
visited[kx][ky] = 1;
for (int i = 0; i < 8; i++) {
int answer = 1 + helper(kx + dx[i], ky + dy[i], pyaada, visited, dp);
mini = min(mini, answer);
}
visited[kx][ky] = 0;
return dp[kx][ky] = mini;
}
int getMinMoves(int kx,int ky ,pair pyaada) {
vector visited(50,vector(50,-1));
vector dp(50,vector(50,-1));
return helper(kx,ky,pyaada,visited,dp);
}
int maxMoves(int kx, int ky, vector& positions) {
bool aliceTurn = true;
int score = 0;
set pyaadePositions;
for(auto itr :positions) {
pyaadePositions.insert({itr[0],itr[1]});
}
while(pyaadePositions.size() >0 ) {
int currentMinMoves =1e9;
int currentMaxMoves =0;
pair minPyaada,maxPyaada;
for(auto position:pyaadePositions) {
int val = getMinMoves(kx,ky,position);
if(val >currentMaxMoves) {
currentMaxMoves = val;
maxPyaada = position;
}
if(val