Submission #1120794

#TimeUsernameProblemLanguageResultExecution timeMemory
1120794coolboy19521Tracks in the Snow (BOI13_tracks)C++17
100 / 100
667 ms143864 KiB
#include"bits/stdc++.h"
using namespace std;
 
const int mxN = 4003;
 
int cl[mxN][mxN];
int g[mxN][mxN];
int H, W;
 
int legal(int i, int j) {
    return 0 <= i && 0 <= j && i < H && j < W && 2 != g[i][j];
}
 
main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    cin >> H >> W;
 
    for (int i = 0; i < H; i ++) {
        for (int j = 0; j < W; j ++) {
            char c;
            cin >> c;
            if ('F' == c) {
                g[i][j] = 1;
            } else if ('.' == c) {
                g[i][j] = 2;
            }
        }
    }
 
    deque<pair<int,int>> pq;
    pq.emplace_back(0, 0);
    cl[0][0] = -1;
 
    int dx[] = {0, 0, 1, -1};
    int dy[] = {1, -1, 0, 0};
    int ans = -1;
 
    while (!pq.empty()) {
        auto [i, j] = pq.front();
        pq.pop_front();
        for (int k = 0; k < 4; k ++) {
            int l = i + dx[k];
            int o = j + dy[k];
            if (legal(l, o) && 0 == cl[l][o]) {
                if (g[l][o] == g[i][j]) {
                    cl[l][o] = cl[i][j];
                    pq.emplace_front(l, o);
                } else {
                    cl[l][o] = cl[i][j] - 1;
                    ans = min(ans, cl[l][o]);
                    pq.emplace_back(l, o);
                }
            }
        }
    }
 
    cout << -ans << endl;
}

Compilation message (stderr)

tracks.cpp:14:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   14 | main() {
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...