이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include"bits/stdc++.h"
using namespace std;
const int mxN = 4003;
int g[mxN][mxN];
main() {
cin.tie(nullptr)->sync_with_stdio(false);
int H, W;
cin >> H >> W;
int allemp = 1;
for (int i = 0; i < H; i ++) {
for (int j = 0; j < W; j ++) {
char c;
cin >> c;
if ('R' == c) {
g[i][j] = 0;
} else if ('F' == c) {
g[i][j] = 1;
} else {
g[i][j] = 2;
}
if ('.' != c) {
allemp = 0;
}
}
}
int ans = 0;
if (allemp) {
cout << 0 << endl;
return 0;
}
while (1) {
ans ++;
int cn[3]{};
for (int i = 0; i < H; i ++) {
for (int j = 0; j < W; j ++) {
cn[g[i][j]] = 1;
}
}
if (1 >= cn[0] + cn[1]) {
break;
}
int c = g[0][0];
g[0][0] = 1 - c;
queue<pair<int,int>> q;
q.emplace(0, 0);
while (!q.empty()) {
auto [i, j] = q.front();
q.pop();
if (i + 1 < H && c == g[i + 1][j]) {
g[i + 1][j] = 1 - c;
q.emplace(i + 1, j);
}
if (j + 1 < W && c == g[i][j + 1]) {
g[i][j + 1] = 1 - c;
q.emplace(i, j + 1);
}
if (0 <= i - 1 && c == g[i - 1][j]) {
g[i - 1][j] = 1 - c;
q.emplace(i - 1, j);
}
if (0 <= j - 1 && c == g[i][j - 1]) {
g[i][j - 1] = 1 - c;
q.emplace(i, j - 1);
}
}
}
cout << ans << endl;
}
컴파일 시 표준 에러 (stderr) 메시지
tracks.cpp:8:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
8 | main() {
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |