이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int n, m;
const int MXN = 1005;
int grid[MXN][MXN];
void place(int a, int b) {
if (grid[a][b] == 0) return;
grid[a][b] = 0;
{
if (grid[a-1][b+1] == 0) {
place(a, b+1);
place(a-1, b);
}
}
{
if (grid[a+1][b-1] == 0) {
place(a+1, b);
place(a, b-1);
}
}
}
int oper(int x, int y) {
if (grid[x][y] == 0) {
place(x, y);
return 1;
}
int tr = 0;
for (int on=1; on<=n; on++) {
int ot = x + y - on;
if (1 <= ot && ot <= m) {
if (grid[on][ot]) tr++;
}
}
if (tr > 1) {
place(x, y);
return 1;
}
else {
return 0;
}
}
signed main() {
cin >> n >> m;
for (int i=1; i<=n; i++) {
for (int j=1; j<=m; j++) {
grid[i][j] = 1;
}
}
int x;
for (int i=1; i<=n; i++) {
for (int j=1; j<=m; j++) {
cin >> x;
if (x == 1) {
oper(i, j);
}
}
}
int q;
cin >> q;
while (q--) {
int x, y;
cin >> x >> y;
cout << oper(x, y) << endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |