#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=1005;
int n,m,q,a[N][N];
bool b[N][N],vis[N][N];
int rec(int x,int y){
if (x>n || y>m || b[x][y]) return a[x][y]=0;
if (x==n && y==m) return a[x][y]=1;
if (vis[x][y]) return a[x][y];
vis[x][y]=true;
return a[x][y]=bool(rec(x+1,y))+bool(rec(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);
/*for (int i=1;i<=n;i++){
for (int j=1;j<=m;++j) cout<<a[i][j]<<' ';
cout<<endl;
}*/
cin>>q;
while (q--){
int x,y;cin>>x>>y;
if ((!b[x-1][y] && a[x-1][y]>1) || (!b[x][y-1] && a[x][y-1]>1) || !a[x][y] || (b[x-1][y] && b[x][y-1])){
cout<<1<<endl;
b[x][y]=true;
a[x-1][y]-=a[x][y];
a[x][y-1]-=a[x][y];
a[x][y]=0;
continue;
}cout<<0<<endl;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
4440 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
4440 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |