Submission #1120473

#TimeUsernameProblemLanguageResultExecution timeMemory
1120473coolboy19521Tracks in the Snow (BOI13_tracks)C++17
73.75 / 100
2108 ms220584 KiB
#include"bits/stdc++.h"
using namespace std;

const int mxN = 4003;

short cl[mxN][mxN];
short g[mxN][mxN];
short 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];
}

main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    cin >> H >> W;

    bool f = true;
    for (register int i = 0; i < H; i ++) {
        for (register int j = 0; j < W; j ++) {
            char c;
            cin >> c;
            if ('F' == c) {
                g[i][j] = 1;
            } else if ('.' == c) {
                g[i][j] = 2;
            }
            if ('F' == c || 'R' == c) {
                f = false;
            }
        }
    }

    if (f) {
        cout << 0 << endl;
        return 0;
    }

    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();
        if (c < ans) {
            ans --;
        }
        pq.pop();
        for (register 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:14:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   14 | main() {
      | ^~~~
tracks.cpp: In function 'int main()':
tracks.cpp:19:23: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   19 |     for (register int i = 0; i < H; i ++) {
      |                       ^
tracks.cpp:20:27: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   20 |         for (register int j = 0; j < W; j ++) {
      |                           ^
tracks.cpp:53:27: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   53 |         for (register int k = 0; k < 4; k ++) {
      |                           ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...