#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#define pb push_back
#define F first
#define S second
#define all(a) a.begin(),a.end()
#define pii pair <int,int>
#define PII pair<pii , pii>
#define ld long double
#define int long long
#define sz(v) (int)v.size()
#define rep(i , a , b) for(int i=a;i <= b;i++)
#define per(i , a , b) for(int i=a;i >= b;i--)
using namespace std ;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxn =2000+10 , N = 1e5 +1 , lg = 20 , maxq = 202 , inf = 1e18 , maxk = 2022 , mod =998244353;
int mark[maxn][maxn] , v[maxn] , n, m ;
int ch(int a ,int b){
if((a==1&&b==1) || (a==n&&b==m))return 0 ;
if(mark[a-1][b] == 0 && mark[a][b-1] == 0)return 1 ;
if(mark[a+1][b] == 0 && mark[a][b+1] == 0)return 1;
return 0 ;
}
int dx[] = {1 , -1 , 0 , 0} , dy[] = {0 , 0 , -1 , 1};
void upd(int x, int y){
mark[x][y] =0 ;
v[x+y]--;
rep(i , 0 , 3){
int a= x+dx[i] , b = y+dy[i] ;
if(mark[a][b] == 1 && ch(a,b) == 1){
upd(a,b) ;
}
}
}
signed main(){
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n >> m ;
vector <pii> vec;
rep(i ,1 ,n){
rep(j ,1 ,m){
char a ;
cin >> a;
if(a=='1')vec.pb({i,j});
v[i+j] ++ ;
mark[i][j] = 1 ;
}
}
for(auto [i,j] : vec)upd(i , j);
int q;
cin >> q ;
while(q--){
int x, y ;
cin >> x >> y;
if(mark[x][y] == 0){
cout << "1\n";
continue ;
}
if(v[x+y]==1){
cout << "0\n";
continue ;
}
upd(x,y) ;
cout << "1\n";
}
}
/*
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |