This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
while (!allemp) {
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;
}
char 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);
}
}
}
cout << ans << endl;
}
Compilation message (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... |