#include <bits/stdc++.h>
using namespace std;
pair<int, int> p[4]={{1, 0}, {-1, 0}, {0, 1}, {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<4; 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';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
380 KB |
Output is correct |
2 |
Incorrect |
139 ms |
424 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
380 KB |
Output is correct |
2 |
Incorrect |
139 ms |
424 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |