#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, m;
vector<vi> a, b;
void calc(){
b[0][0] = 1;
FOR(i,n) b[i][0] = a[i][0]==0;
FOR(i,m) b[0][i] = a[0][i]==0;
FORi(i,1,n){
FORi(j,1,m){
if(a[i][j]) b[i][j] = 0;
else b[i][j] = b[i-1][j] + b[i][j-1];
}
}
assert(b[n-1][m-1]!=0);
}
int main(){
cin>>n>>m;
b.assign(n, vi(m));
a.assign(n, vi(m));
FOR(i,n){
FOR(j,m) cin>>a[i][j];
}
int q;
cin>>q;
calc();
/*
FOR(i,n){
FOR(j,m) cout<<b[i][j]<<" ";
cout<<endl;
}*/
while(q--){
int x,y;
cin>>x>>y;
if(b[n-1][m-1]!=b[x-1][y-1]){
cout<<1<<endl, a[x-1][y-1] = 1;
calc();
}
else cout<<0<<endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
332 KB |
Output is correct |
2 |
Runtime error |
7 ms |
460 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
332 KB |
Output is correct |
2 |
Runtime error |
7 ms |
460 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |