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>
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |