#include <bits/stdc++.h>
using namespace std;
pair<int, int> p[2]={{1, 0}, {0, 1}};
int a[105][105], visited[105][105];
queue<pair<int, int> > q;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m, o;
cin >> n >> m;
for (int i=1; i<=n; i++)
for (int j=1; j<=m; j++)
cin >> a[i][j];
cin >> o;
for (int i=1; i<=o; i++)
{
int x, y;
cin >> x >> y;
a[x][y]=1;
for (int j=1; j<=n; j++)
for (int k=1; k<=m; k++)
visited[j][k]=0;
visited[1][1]=1;
q.push({1, 1});
while (!q.empty())
{
int ux=q.front().first, uy=q.front().second;
q.pop();
// cout << "ux uy " << ux << ' ' << uy << '\n';
for (int j=0; j<2; j++)
{
int vx=ux+p[j].first, vy=uy+p[j].second;
if (1<=vx && vx<=n && 1<=vy && vy<=m && !visited[vx][vy] && !a[vx][vy])
{
visited[vx][vy]=1;
q.push({vx, vy});
}
}
}
if (!visited[n][m])
a[x][y]=0;
cout << a[x][y] << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
340 KB |
Output is correct |
2 |
Correct |
29 ms |
340 KB |
Output is correct |
3 |
Correct |
112 ms |
340 KB |
Output is correct |
4 |
Correct |
181 ms |
468 KB |
Output is correct |
5 |
Correct |
203 ms |
468 KB |
Output is correct |
6 |
Correct |
392 ms |
596 KB |
Output is correct |
7 |
Correct |
138 ms |
612 KB |
Output is correct |
8 |
Correct |
197 ms |
480 KB |
Output is correct |
9 |
Correct |
471 ms |
608 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
340 KB |
Output is correct |
2 |
Correct |
29 ms |
340 KB |
Output is correct |
3 |
Correct |
112 ms |
340 KB |
Output is correct |
4 |
Correct |
181 ms |
468 KB |
Output is correct |
5 |
Correct |
203 ms |
468 KB |
Output is correct |
6 |
Correct |
392 ms |
596 KB |
Output is correct |
7 |
Correct |
138 ms |
612 KB |
Output is correct |
8 |
Correct |
197 ms |
480 KB |
Output is correct |
9 |
Correct |
471 ms |
608 KB |
Output is correct |
10 |
Incorrect |
1998 ms |
872 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |