This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define DIM 1010
using namespace std;
int a[DIM][DIM],viz[DIM][DIM],cnt[DIM*2];
int n,m,i,j,q,x,y;
void mark (int i, int j){
if (i <= 0 || i > n || j <= 0 || j > m)
return;
if (a[i][j])
return;
a[i][j] = 1;
cnt[i+j]--;
if (i == 1 || j == m || a[i-1][j+1]){
mark (i,j+1);
mark (i-1,j);
}
if (i == n || j == 1 || a[i+1][j-1]){
mark (i+1,j);
mark (i,j-1);
}
}
int main (){
//ifstream cin ("date.in");
//ofstream cout ("date.out");
cin>>n>>m;
/// cnt[i] - in cate locuri de pe diagonala secundara i pot sa ajung
for (i=1;i<=n;i++)
for (j=1;j<=m;j++)
cnt[i+j]++;
for (i=1;i<=n;i++)
for (j=1;j<=m;j++){
cin>>x;
if (x)
mark (i,j);
}
cin>>q;
for (;q--;){
cin>>x>>y;
if (a[x][y]){
cout<<"1\n";
continue;
}
if (cnt[x+y] == 1){
cout<<"0\n";
continue;
}
cout<<"1\n";
mark(x,y);
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |