//In the name of GOD
#include <bits/stdc++.h>
using namespace std;
const int maxN=1e3+5;
int n, m, q, dp[maxN][maxN];
bool c[maxN][maxN];
int main(){
cin >>n >>m;
for (int i=1; i<=n; i++)
for (int j=1; j<=m; j++)
cin >>c[i][j];
cin >>q;
while(q--){
int x, y;
cin >>x >>y;
c[x][y]=true;
dp[n][m]=1;
for (int i=n; i>=1; i--)
for (int j=m; j>=1; j--)
if(i!=n or j!=m) dp[i][j]=(c[i][j] ? 0 : dp[i+1][j]+dp[i][j+1]);
if(dp[1][1]==0){
cout <<"0\n";
c[x][y]=false;
}
else cout <<"1\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |