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 fr first
#define sc second
#define pii pair<int, int>
#define pb push_back
#define szof(s) (int)s.size()
#define all(s) s.begin(), s.end()
#define fastInp ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
const int MAXN = 1003;
char ch[MAXN][MAXN];
int n, m;
int dp[MAXN][MAXN];
int id = 0;
bool check() {
id++;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (i == 1 && j == 1) {
dp[i][j] = id;
}
else if (ch[i][j] != '1') {
if (i > 1) {
dp[i][j] = max(dp[i][j], dp[i - 1][j]);
}
if (j > 1) {
dp[i][j] = max(dp[i][j], dp[i][j - 1]);
}
}
}
}
return (dp[n][m] == id);
}
signed main() {
//fastInp;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> ch[i][j];
}
}
int q;
cin >> q;
while (q--) {
int i, j;
cin >> i >> j;
ch[i][j] = '1';
if (check()) {
cout << 1 << endl;
} else {
cout << 0 << endl;
ch[i][j] = '0';
}
}
}
/*
1 case:
2 3
0 0 1
0 0 0
3
2 2
2 1
1 2
2 case:
2 5
0 0 0 0 0
0 0 0 1 0
2
1 2
2 2
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |