#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e3 + 10;
int c[MAXN][MAXN];
bool dp[MAXN][MAXN];
signed main()
{
int n, m, q;
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
cin >> c[i][j];
}
}
cin >> q;
while (q--)
{
int x, y;
cin >> x >> y;
c[x][y] = 1;
dp[1][1] = true;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
if (i == 1 && j == 1)
continue;
dp[i][j] = false;
if (i > 1)
dp[i][j] |= dp[i - 1][j];
if (j > 1)
dp[i][j] |= dp[i][j - 1];
if (c[i][j] == 1)
dp[i][j] = false;
}
}
if (dp[n][m])
{
cout << 1 << endl;
}
else
{
c[x][y] = 0;
cout << 0 << endl;
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |