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 "iostream"
#include "queue"
#include "tuple"
using namespace std;
const int mxN = 4003;
int cl[mxN][mxN];
int g[mxN][mxN];
int H, W;
bool legal(int i, int j) {
return 0 <= i && 0 <= j && i < H && j < W && 2 != g[i][j] && 0 == cl[i][j];
}
int main() {
cin >> H >> W;
for (int i = 0; i < H; i ++) {
for (int j = 0; j < W; j ++) {
char c;
scanf("%c", &c);
if ('F' == c) {
g[i][j] = 1;
} else if ('.' == c) {
g[i][j] = 2;
}
}
}
priority_queue<tuple<int,int,int>> pq;
pq.emplace(-1, 0, 0);
cl[0][0] = -1;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int ans = 0;
while (!pq.empty()) {
auto [c, i, j] = pq.top();
ans = c;
pq.pop();
for (int k = 0; k < 4; k ++) {
int l = i + dx[k];
int o = j + dy[k];
if (legal(l, o)) {
if (g[l][o] == g[i][j]) {
cl[l][o] = c;
pq.emplace(c, l, o);
} else {
cl[l][o] = c - 1;
pq.emplace(c - 1, l, o);
}
}
}
}
cout << -ans << endl;
}
Compilation message (stderr)
tracks.cpp: In function 'int main()':
tracks.cpp:22:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
22 | scanf("%c", &c);
| ~~~~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |