This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vii;
typedef pair<ll,ll> pii;
#define F first
#define S second
#define pb push_back
#define all(v) v.begin(),v.end()
const ll M=1001;
ll n,m;
bool a[M][M];
int c[M][M];
bool chk(ll x=0,ll y=0){
if(x==n-1&&y==m-1)
return 1;
if(c[x][y]>-1)
return c[x][y];
if(a[x][y])
return 0;
bool res=0;
if(x<n-1)
res|=chk(x+1,y);
if(y<m-1)
res|=chk(x,y+1);
c[x][y]=res;
return res;
}
int main(){
ios_base::sync_with_stdio(0),cin.tie(0);
cin>>n>>m;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++)
cin>>a[i][j];
}
ll q;
cin>>q;
while(q--){
for(int i=0;i<n;i++){
for(int j=0;j<m;j++)
c[i][j]=-1;
}
ll x,y;
cin>>x>>y;
x--,y--;
a[x][y]=1;
if(chk())
cout<<1<<'\n';
else{
cout<<0<<'\n';
a[x][y]=0;
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |