Help me in solving N1 problem

My issue

My code

#include <iostream>
using namespace std;

int main() {
	// your code goes here
	return 0;
}

Problem Link: N1 Problem - CodeChef
how to keep track if we can visit any cell any number of times and also in any direction