β Balanced Neighborhood (Contest)
Balanced Neighborhood (Contest) easy Time Limit: 2 sec Memory Limit: 128000 kB
import java.io.*; // for handling input/output
import java.util.*; // contains Collections framework
// don't change the name of this class
// you can add inner classes if needed
class Main {
public static void main (String[] args) {
// Your code here
Scanner sc = new Scanner(System.in);
int n=sc.nextInt();
int m = sc.nextInt();
int[][] a = new int[n][m];
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
a[i][j] = sc.nextInt();
}
}
for(int i=1;i<n-1;i++)
{
for(int j =1;j<m-1;j++)
{
if((a[i-1][j] + a[i+1][j]+a[i][j-1]+a[i][j+1])%2 != 0){
System.out.print("NO");
return;
}
}
}
System.out.print("YES");
}
}Last updated