#include<bits/stdc++.h>
using namespace std;
int dx[] {1, 0, -1, 0};
int dy[] {0, 1, 0, -1};
void PlayGround() {
int n, m;
cin>>n>>m;
int a[n+1][m+1];
bool vis[n+1][m+1];
for(int i=1; i<=n; ++i) {
for(int j=1; j<=m; ++j) {
cin>>a[i][j];
}
}
auto valid = [&] (int x, int y) {
return min(x, y)>=1 && x<=n && y<=m;
};
int q;
cin>>q;
while(q--) {
int x, y;
cin>>x>>y;
a[x][y] = 1;
memset(vis, 0, sizeof vis);
queue<pair<int,int>>q;
q.emplace(1, 1);
while(!q.empty()) {
auto [x, y] = q.front();
q.pop();
if(vis[x][y]) continue;
vis[x][y] = true;
for(int k=0; k<2; ++k) {
int nx = x + dx[k], ny = y + dy[k];
if(valid(nx, ny) && a[nx][ny]==0) {
q.emplace(nx, ny);
}
}
}
if(!vis[n][m]) {
cout<<"0\n";
a[x][y] = 0;
} else {
cout<<"1\n";
}
}
// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
PlayGround();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
340 KB |
Output is correct |
2 |
Correct |
21 ms |
336 KB |
Output is correct |
3 |
Correct |
101 ms |
380 KB |
Output is correct |
4 |
Correct |
156 ms |
536 KB |
Output is correct |
5 |
Correct |
180 ms |
420 KB |
Output is correct |
6 |
Correct |
327 ms |
436 KB |
Output is correct |
7 |
Correct |
96 ms |
432 KB |
Output is correct |
8 |
Correct |
141 ms |
432 KB |
Output is correct |
9 |
Correct |
427 ms |
576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
340 KB |
Output is correct |
2 |
Correct |
21 ms |
336 KB |
Output is correct |
3 |
Correct |
101 ms |
380 KB |
Output is correct |
4 |
Correct |
156 ms |
536 KB |
Output is correct |
5 |
Correct |
180 ms |
420 KB |
Output is correct |
6 |
Correct |
327 ms |
436 KB |
Output is correct |
7 |
Correct |
96 ms |
432 KB |
Output is correct |
8 |
Correct |
141 ms |
432 KB |
Output is correct |
9 |
Correct |
427 ms |
576 KB |
Output is correct |
10 |
Correct |
4855 ms |
1104 KB |
Output is correct |
11 |
Correct |
203 ms |
412 KB |
Output is correct |
12 |
Execution timed out |
5039 ms |
6980 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |