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>
#define fastio ios_base :: sync_with_stdio(0), cin.tie(0);
using namespace std;
using ll = long long;
const int mxN = 1e3 + 5, mod = 1e9 + 7;
int n, m, a[mxN][mxN];
bool dp[mxN][mxN];
int main() {
fastio;
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) cin >> a[i][j];
}
int q;
cin >> q;
while (q--) {
int x, y;
cin >> x >> y;
a[x][y] = 1;
dp[1][1] = 1;
for (int i = 1; i <= n; ++i) {
for (int j = 1 + (i == 1); j <= m; ++j) {
dp[i][j] = 0;
if (a[i][j]) continue;
dp[i][j] = (dp[i - 1][j] | dp[i][j - 1]);
}
}
if (dp[n][m])
cout << "1\n";
else
a[x][y] = 0, cout << "0\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |