💡 Funky Chess Board

what’s wrong with test case #3
TESTCASE # 1 : correct (Time: 0.01 s)
TESTCASE # 2 : correct (Time: 0 s)
TESTCASE # 3 : wrong-answer (Time: 0 s)
plz judge my code.


#include<iostream>
#include <vector>
using namespace std;
#define f first 
#define s second
int grid[10][10];
int ans=0;
int n;
std::vector<pair<int, int>> moves = {
							{-2, -1}, {-2, 1},
							{-1, -2}, {-1, 2},
							{ 1, -2}, { 1, 2},
							{ 2, -1}, { 2, 1}};

void go(int x, int y,int count ){
	ans = max(ans, count);

	for(pair<int,int> &i:moves){
		if((x+i.f) >= 0 && (y+i.s) >= 0 && (x+i.f) < n && (y+i.s)< n){
			if(grid[x+i.f][y+i.s]==1){
				grid[x+i.f][y+i.s] = 0;
				go( x+i.f, y+i.s, count+1);
				grid[x+i.f][y+i.s] = 1;
			}
		}
	}


}
int main() {
	int t,sum=0;
    cin>>t;
    n = t;
    for(int i=0;i<t;i++)
        for(int j=0;j<t;j++){

            cin>>grid[i][j];
        	if(grid[i][j])
        		sum++;
        }
    go( 0, 0, 0);
    cout<<sum - ans;
    return 0;
}

Hey Pradeep
Just a slight mistake
Since you’re starting at 0,0 you need to mark 0,0 as 0 as well in the beginning and add 1 for that to your count of visited cells.

1 Like

thank you @Aarnav-Jindal-1059677350830863 :hugs:

1 Like