| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 492090 | alextodoran | Furniture (JOI20_furniture) | C++17 | 277 ms | 4164 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/**
____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int NM_MAX = 1000;
int N, M;
bool inPath[NM_MAX + 2][NM_MAX + 2];
int sumCount[NM_MAX * 2 + 2];
int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
bool inside (int x, int y) {
return (1 <= x && x <= N && 1 <= y && y <= M);
}
bool check (int x, int y) {
if (x == 1 && y == 1 || x == N && y == M) {
return true;
}else if (inPath[x + 1][y] == false && inPath[x][y + 1] == false) {
return false;
} else if (inPath[x - 1][y] == false && inPath[x][y - 1] == false) {
return false;
} else {
return true;
}
}
bool placeBlock (int X, int Y) {
if (inPath[X][Y] == false) {
return true;
}
if (sumCount[X + Y] == 1) {
return false;
}
queue <pair <int, int>> q;
inPath[X][Y] = false;
sumCount[X + Y]--;
q.push(make_pair(X, Y));
while (q.empty() == false) {
int x = q.front().first;
int y = q.front().second;
q.pop();
for (int d = 0; d < 4; d++) {
int x1 = x + dx[d], y1 = y + dy[d];
if (inside(x1, y1) == true && inPath[x1][y1] == true && check(x1, y1) == false) {
inPath[x1][y1] = false;
sumCount[x1 + y1]--;
q.push(make_pair(x1, y1));
}
}
}
return true;
}
int Q;
int main () {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> N >> M;
for (int x = 1; x <= N; x++) {
for (int y = 1; y <= M; y++) {
inPath[x][y] = true;
sumCount[x + y]++;
}
}
for (int x = 1; x <= N; x++) {
for (int y = 1; y <= M; y++) {
bool init;
cin >> init;
if (init == true) {
assert(placeBlock(x, y) == true);
}
}
}
cin >> Q;
while (Q--) {
int X, Y;
cin >> X >> Y;
cout << placeBlock(X, Y) << "\n";
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
