#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int N = 2000 + 7;
int n;
int m;
int a[N][N];
bool down[N][N];
bool up[N][N];
bool on[N][N];
int cnt[2 * N];
void init()
{
for (int i = 1; i <= n + m; i++)
{
cnt[i] = 0;
}
down[n + 1][m] = 1;
up[1][0] = 1;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
if (a[i][j] == 0)
{
up[i][j] = up[i - 1][j] | up[i][j - 1];
}
else
{
up[i][j] = 0;
}
}
}
for (int i = n; i >= 1; i--)
{
for (int j = m; j >= 1; j--)
{
if (a[i][j] == 0)
{
down[i][j] = down[i + 1][j] | down[i][j + 1];
}
else
{
down[i][j] = 0;
}
}
}
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
if (up[i][j] && down[i][j])
{
cnt[i + j]++;
on[i][j] = 1;
}
}
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
///freopen ("input", "r", stdin);
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
cin >> a[i][j];
}
}
init();
int q;
cin >> q;
while (q--)
{
int r, c;
cin >> r >> c;
if (on[r][c] == 0)
{
cout << "1\n";
continue;
}
if (cnt[r + c] == 1)
{
cout << "0\n";
continue;
}
cout << "1\n";
a[r][c] = 1;
init();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
1024 KB |
Output is correct |
2 |
Incorrect |
11 ms |
1408 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
1024 KB |
Output is correct |
2 |
Incorrect |
11 ms |
1408 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |