#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=105;
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) return a[x][y]=1;
if (x>n || x<1 || y>m || y<1 || b[x][y]) return a[x][y]=INT_MAX;
if (vis[x][y]) return a[x][y];
vis[x][y]=true;
return a[x][y]=bool(rec(x+1,y)<INT_MAX && rec(x+1,y)>0)+bool(rec(x,y+1)<INT_MAX && rec(x,y+1)>0);
}
int32_t main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
//for (int i=0;i<N;i++) for (int j=0;j<N;j++) a[i][j]=INT_MAX;
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++) if (!b[i][j] && a[i][j]>=INT_MAX) a[i][j]=0;
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;
b[x][y]=true;
memset(vis,0,sizeof(vis));
vis[n][m]=true;
for (int i=n;i;i--){
for (int j=m;j;j--){
if (b[i][j] || !vis[i][j]) continue;
vis[i-1][j]=!b[i-1][j];
vis[i][j-1]=!b[i][j-1];
}
}
/*for (int i=1;i<=n;i++){
for (int j=1;j<=m;j++) cout<<vis[i][j];
cout<<endl;
}*/
b[x][y]=vis[1][1];
cout<<b[x][y]<<endl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
344 KB |
Output is correct |
2 |
Correct |
24 ms |
348 KB |
Output is correct |
3 |
Correct |
70 ms |
600 KB |
Output is correct |
4 |
Correct |
149 ms |
344 KB |
Output is correct |
5 |
Correct |
160 ms |
344 KB |
Output is correct |
6 |
Correct |
215 ms |
544 KB |
Output is correct |
7 |
Correct |
133 ms |
560 KB |
Output is correct |
8 |
Correct |
111 ms |
536 KB |
Output is correct |
9 |
Correct |
118 ms |
552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
344 KB |
Output is correct |
2 |
Correct |
24 ms |
348 KB |
Output is correct |
3 |
Correct |
70 ms |
600 KB |
Output is correct |
4 |
Correct |
149 ms |
344 KB |
Output is correct |
5 |
Correct |
160 ms |
344 KB |
Output is correct |
6 |
Correct |
215 ms |
544 KB |
Output is correct |
7 |
Correct |
133 ms |
560 KB |
Output is correct |
8 |
Correct |
111 ms |
536 KB |
Output is correct |
9 |
Correct |
118 ms |
552 KB |
Output is correct |
10 |
Incorrect |
1490 ms |
760 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |