#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1000;
int mat[MAX_N + 2][MAX_N + 2];
int main() {
int n, m;
cin >> n >> m;
for ( int l = 0; l <= n + 1; l++ )
mat[l][0] = mat[l][m + 1] = 1;
for ( int c = 0; c <= m + 1; c++ )
mat[0][c] = mat[n + 1][c] = 1;
for ( int l = 1; l <= n; l++ ) {
for ( int c = 1; c <= m; c++ )
cin >> mat[l][c];
}
int v = 0, e = 0, f = 0;
for ( int l = 1; l <= n; l++ ) {
for ( int c = 1; c <= m; c++ ) {
if ( mat[l][c] == 0 ) {
v++;
if ( mat[l][c + 1] == 0 )
e++;
if ( mat[l + 1][c] == 0 )
e++;
if ( mat[l + 1][c] + mat[l][c + 1] + mat[l + 1][c + 1] == 0 )
f++;
}
}
}
int q;
cin >> q;
while ( q-- ) {
int l, c;
cin >> l >> c;
int cv = v, ce = e, cf = f;
v--;
if ( mat[l][c + 1] == 0 )
e--;
if ( mat[l][c - 1] == 0 )
e--;
if ( mat[l + 1][c] == 0 )
e--;
if ( mat[l - 1][c] == 0 )
e--;
if ( mat[l - 1][c] + mat[l][c - 1] + mat[l - 1][c - 1] == 0 )
f--;
if ( mat[l + 1][c] + mat[l][c - 1] + mat[l + 1][c - 1] == 0 )
f--;
if ( mat[l - 1][c] + mat[l][c + 1] + mat[l - 1][c + 1] == 0 )
f--;
if ( mat[l + 1][c] + mat[l][c + 1] + mat[l + 1][c + 1] == 0 )
f--;
mat[l][c] = 1;
if ( v - e + f == 1 )
cout << "1\n";
else {
cout << "0\n";
v = cv;
e = ce;
f = cf;
mat[l][c] = 0;
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2652 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2652 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |