#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define ppb pop_back
#define ep insert
#define endl '\n'
#define elif else if
#define pow pwr
#define sqrt sqrtt
//#define int long long
#define y1 YONE
typedef unsigned long long ull;
using namespace std;
const int N=3005;
int n,m,q,a[N][N],d[N][N],c,vis[N][N],f[N];
bool b[N][N],dp[N][N];
bool rec(int x,int y,int dd){
if (x>n || y>m || b[x][y]) return 0;
if (x==n && y==m){
d[x][y]=dd;
return 1;
}
if (vis[x][y]) return dp[x][y];
vis[x][y]=-1;
dp[x][y]=rec(x+1,y,dd+1)|rec(x,y+1,dd+1);
d[x][y]=dd*dp[x][y];
f[d[x][y]]++;
return dp[x][y];
}
void dfs1(int x,int y){
f[d[x][y]]--;
d[x][y]=0;
if (x<n && !d[x+1][y-1] && d[x+1][y]) dfs1(x+1,y);
if (y<m && !d[x-1][y+1] && d[x][y+1]) dfs1(x,y+1);
return;
}
void dfs2(int x,int y){
vis[x][y]=c;
if (!d[x+1][y] && !d[x][y+1]) f[d[x][y]]--,d[x][y]=0;
if (d[x][y]) return;
if (x>1 && vis[x-1][y]!=c) dfs2(x-1,y);
if (y>1 && vis[x][y-1]!=c) dfs2(x,y-1);
}
int32_t main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
cin>>n>>m;
for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) cin>>b[i][j];
rec(1,1,0);
/*for (int i=1;i<=n;i++){
for (int j=1;j<=m;j++) cout<<d[i][j]<<' ';
cout<<endl;
}*/
cin>>q;
while (q--){
c++;
int x,y;cin>>x>>y;
if (!d[x][y]){
b[x][y]=true;
cout<<1<<endl;
continue;
}
if (f[d[x][y]]>1){
for (int i=1;i<=10;i++){
dfs2(x,y);
dfs1(x,y);}
b[x][y]=true;
cout<<1<<endl;
continue;
}cout<<0<<endl;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
9052 KB |
Output is correct |
2 |
Incorrect |
2 ms |
9052 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
9052 KB |
Output is correct |
2 |
Incorrect |
2 ms |
9052 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |