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 long double ld;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int LIM=1e3+7, INF=1e9+7;
int T[LIM][LIM], dp[LIM][LIM], uzyte[LIM][LIM], ans[LIM*LIM], n, m;
pair<int,int>P[LIM*LIM];
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> m;
rep(i, n) rep(j, m) {
T[i][j]=INF;
int a;
cin >> a;
if(a) T[i][j]=-1;
}
int q;
cin >> q;
rep(i, q) {
ans[i]=1;
int a, b;
cin >> a >> b; --a; --b;
T[a][b]=i;
P[i]={a, b};
}
rep(i, n+1) dp[i][0]=-1;
rep(i, m+1) dp[0][i]=-1;
dp[0][1]=dp[1][0]=INF;
while(true) {
rep(i, n) rep(j, m) {
dp[i+1][j+1]=min(T[i][j], max(dp[i][j+1], dp[i+1][j]));
}
if(dp[n][m]==INF) break;
ans[dp[n][m]]=0;
T[P[dp[n][m]].st][P[dp[n][m]].nd]=INF;
}
rep(i, q) cout << ans[i] << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |