#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pf push_front
#define fi first
#define se second
const ll mod = 1e9+7, mxn = 1007;
bool blocked[mxn][mxn];
ll dia[mxn<<1], n, m;
void block(ll i, ll j)
{
blocked[i][j] = 1; dia[i+j]--;
if ((i-1 >= 1 && !blocked[i-1][j]))
{
if (i-1 >= 1 && j+1 <= m) {if (blocked[i-1][j+1]) block(i-1,j);}
else block(i-1,j);
}
if ((i+1 <= n && !blocked[i+1][j]))
{
if (i+1 <= n && j-1 >= 1) {if (blocked[i+1][j-1]) block(i+1,j);}
else block(i+1,j);
}
if ((j-1 >= 1 && !blocked[i][j-1]))
{
if (i+1 <= n && j-1 >= 1) {if (blocked[i+1][j-1]) block(i,j-1);}
else block(i,j-1);
}
if ((j+1 <= m && !blocked[i][j+1]))
{
if (i-1 >= 1 && j+1 <= m) {if (blocked[i-1][j+1]) block(i,j+1);}
else block(i,j+1);
}
}
signed main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// freopen("test.inp","r",stdin); freopen("test.out","w",stdout); freopen("test.err","w",stderr);
cin >> n >> m; // cerr << n << ' ' << m << '\n';
for (ll i = 1; i <= n; i++) for (ll j = 1; j <= m; j++) dia[i+j]++;
for (ll i = 1; i <= n; i++) for (ll j = 1; j <= m; j++) {ll x; cin >> x; if (x) if (!(dia[i+j] == 1 && !blocked[i][j]) && !(blocked[i][j])) block(i,j);}
ll q; cin >> q;
while (q--)
{
ll x, y; cin >> x >> y;
if (dia[x+y] == 1 && !blocked[x][y]) cout << "0" << '\n';
else cout << "1" << '\n';
if (!blocked[x][y]) block(x,y);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |