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;
#define mp make_pair
#define INF 10000000
#define MOD 1000000007
#define MID ((l+r)/2)
#define HASHMOD 2305843009213693951
#define ll long long
#define ull unsigned long long
#define F first
#define S second
typedef pair<ll, ll> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef map<int, int> mii;
#define EPS 1e-6
#define FOR(i,n) for(int i=0;i<((int)(n));i++)
#define FORi(i,a,b) for(int i=((int)(a));i<((int)(b));i++)
#define FOA(v, a) for(auto v : a)
int t, n;
vi a, b;
int main(){
int n, m;
cin>>n>>m;
vector<vi> a(n, vi(m));
FOR(i,n){
FOR(j,m) cin>>a[i][j];
}
int q;
cin>>q;
while(q--){
int x,y;
cin>>x>>y;
vector<vi> b(n, vi(m));
b[0][0] = 1;
FORi(i,1,n) b[i][0] = b[i-1][0] && (a[i][0]==0 && !(x-1==i && y==1));
FORi(i,1,m) b[0][i] = b[0][i-1] && (a[0][i]==0 && !(x==1 && i==y-1));
FORi(i,1,n){
FORi(j,1,m){
b[i][j] = b[i-1][j]+b[i][j-1];
if(a[i][j]) b[i][j] = 0;
if(i==x-1 && j==y-1) b[i][j] = 0;
}
}
if(b[n-1][m-1]) cout<<1<<endl, a[x-1][y-1] = 1;
else cout<<0<<endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |