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>
using namespace std;
const int N=1003;
bool f[N][N];
int a,n,m,q,x,y,d[2*N];
void Dfs(int a,int b);
void M(int a,int b);
void Dfs(int x,int y) {
if (!f[x-1][y+1]) {
M(x,y+1);
M(x-1,y);
}
if (!f[x+1][y-1]) {
M(x,y-1);
M(x+1,y);
}
}
void M(int x,int y) {
if (f[x][y]) {
f[x][y]=false;
--d[x+y];
Dfs(x,y);
}
}
main () {
cin>>n>>m;
for (int i=1; i<=n; i++)
for (int j=1; j<=m; j++)
f[i][j]=true,d[i+j]++;
for (int i=1; i<=n; i++) {
for (int j=1; j<=m; j++) {
cin>>a;
if (a && f[i][j])
M(i,j);
}
}
cin>>q;
for (int i=1; i<=q; i++) {
cin>>x>>y;
if (!f[x][y]) {
cout<<1<<"\n";
continue;
}
if (d[x+y]==1) {
cout<<0<<"\n";
continue;
}
cout<<1<<"\n";
M(x,y);
}
}
Compilation message (stderr)
furniture.cpp:33:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
33 | main () {
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |