#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define all(x) x.begin(), x.end()
int main() {
ios::sync_with_stdio(false), cin.tie(0);
int n, m, q;
cin >> n >> m;
vector <vector <bool>> is(n, vector <bool>(m, false));
for (int i = 0; i < n; ++i) {
for (int j = 0, x; j < m; ++j) {
cin >> x, is[i][j] = x;
}
}
vector <vector <bool>> dp(n, vector <bool>(m, false));
auto chk = [&]() {
dp.assign(n, vector <bool>(m, false));
dp[0][0] = true;
for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) if (dp[i][j]) {
if (i + 1 < n && !is[i + 1][j]) {
dp[i + 1][j] = true;
}
if (j + 1 < m && !is[i][j + 1]) {
dp[i][j + 1] = true;
}
}
};
cin >> q;
while (q--) {
int x, y;
cin >> x >> y, --x, --y;
is[x][y] = true;
chk();
if (dp[n - 1][m - 1]) {
cout << "1\n";
} else {
cout << "0\n";
is[x][y] = false;
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
340 KB |
Output is correct |
2 |
Correct |
67 ms |
352 KB |
Output is correct |
3 |
Correct |
91 ms |
368 KB |
Output is correct |
4 |
Correct |
198 ms |
384 KB |
Output is correct |
5 |
Correct |
216 ms |
396 KB |
Output is correct |
6 |
Correct |
309 ms |
404 KB |
Output is correct |
7 |
Correct |
246 ms |
528 KB |
Output is correct |
8 |
Correct |
236 ms |
416 KB |
Output is correct |
9 |
Correct |
281 ms |
416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
340 KB |
Output is correct |
2 |
Correct |
67 ms |
352 KB |
Output is correct |
3 |
Correct |
91 ms |
368 KB |
Output is correct |
4 |
Correct |
198 ms |
384 KB |
Output is correct |
5 |
Correct |
216 ms |
396 KB |
Output is correct |
6 |
Correct |
309 ms |
404 KB |
Output is correct |
7 |
Correct |
246 ms |
528 KB |
Output is correct |
8 |
Correct |
236 ms |
416 KB |
Output is correct |
9 |
Correct |
281 ms |
416 KB |
Output is correct |
10 |
Correct |
3476 ms |
632 KB |
Output is correct |
11 |
Correct |
124 ms |
380 KB |
Output is correct |
12 |
Execution timed out |
5083 ms |
2432 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |