답안 #962614

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
962614 2024-04-14T02:52:57 Z novus677 Tracks in the Snow (BOI13_tracks) C++14
89.0625 / 100
2000 ms 73024 KB
#include <iostream>
#include <queue>
#include <tuple>
#include <vector>

using namespace std;

int H, W;
char grid[4000][4000];
bool visited[4000][4000];
char cur;

int main() {
    cin >> H >> W;

    for (int i = 0; i < H; ++i) {
        string row;
        cin >> row;
        for (int j = 0; j < W; ++j) {
            grid[i][j] = row[j];
        }
    }
    cur = grid[0][0];

    int answer = 1;
    priority_queue<tuple<int, int, int>> queue;
    queue.push({-1, 0, 0});
    visited[0][0] = true;
    while (!queue.empty()) {
        auto [marker, i, j] = queue.top();
        queue.pop();
        answer = max(answer, -marker);

        if (i > 0 && !visited[i - 1][j]) {
            if (grid[i - 1][j] == grid[i][j]) {
                visited[i - 1][j] = true;
                queue.push({marker, i - 1, j});
            } else if (grid[i - 1][j] != '.') {
                visited[i - 1][j] = true;
                queue.push({marker - 1, i - 1, j});
            }
        }
        if (i < H - 1 && !visited[i + 1][j]) {
            if (grid[i + 1][j] == grid[i][j]) {
                visited[i + 1][j] = true;
                queue.push({marker, i + 1, j});
            } else if (grid[i + 1][j] != '.') {
                visited[i + 1][j] = true;
                queue.push({marker - 1, i + 1, j});
            }
        }
        if (j > 0 && !visited[i][j - 1]) {
            if (grid[i][j - 1] == grid[i][j]) {
                visited[i][j - 1] = true;
                queue.push({marker, i, j - 1});
            } else if (grid[i][j - 1] != '.') {
                visited[i][j - 1] = true;
                queue.push({marker - 1, i, j - 1});
            }
        }
        if (j < W - 1 && !visited[i][j + 1]) {
            if (grid[i][j + 1] == grid[i][j]) {
                visited[i][j + 1] = true;
                queue.push({marker, i, j + 1});
            } else if (grid[i][j + 1] != '.') {
                visited[i][j + 1] = true;
                queue.push({marker - 1, i, j + 1});
            }
        }
    }

    cout << answer << '\n';
}

Compilation message

tracks.cpp: In function 'int main()':
tracks.cpp:30:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   30 |         auto [marker, i, j] = queue.top();
      |              ^
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 6748 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 2 ms 2652 KB Output is correct
4 Correct 27 ms 7000 KB Output is correct
5 Correct 5 ms 5724 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 4 ms 2648 KB Output is correct
8 Correct 2 ms 2652 KB Output is correct
9 Correct 3 ms 2652 KB Output is correct
10 Correct 6 ms 5468 KB Output is correct
11 Correct 8 ms 3420 KB Output is correct
12 Correct 15 ms 5724 KB Output is correct
13 Correct 5 ms 5720 KB Output is correct
14 Correct 5 ms 5724 KB Output is correct
15 Correct 35 ms 6836 KB Output is correct
16 Correct 46 ms 6744 KB Output is correct
17 Correct 19 ms 6488 KB Output is correct
18 Correct 27 ms 7004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 31324 KB Output is correct
2 Correct 108 ms 13080 KB Output is correct
3 Correct 434 ms 47440 KB Output is correct
4 Correct 142 ms 21684 KB Output is correct
5 Correct 195 ms 35356 KB Output is correct
6 Execution timed out 2033 ms 72508 KB Time limit exceeded
7 Correct 10 ms 31580 KB Output is correct
8 Correct 10 ms 31324 KB Output is correct
9 Correct 5 ms 2652 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 11 ms 31312 KB Output is correct
12 Correct 2 ms 2904 KB Output is correct
13 Correct 106 ms 12988 KB Output is correct
14 Correct 62 ms 10844 KB Output is correct
15 Correct 21 ms 11488 KB Output is correct
16 Correct 55 ms 6748 KB Output is correct
17 Correct 285 ms 22624 KB Output is correct
18 Correct 94 ms 22196 KB Output is correct
19 Correct 133 ms 21588 KB Output is correct
20 Correct 103 ms 18876 KB Output is correct
21 Correct 265 ms 36048 KB Output is correct
22 Correct 186 ms 35152 KB Output is correct
23 Correct 553 ms 30256 KB Output is correct
24 Correct 204 ms 35896 KB Output is correct
25 Correct 379 ms 47540 KB Output is correct
26 Correct 1391 ms 42712 KB Output is correct
27 Execution timed out 2024 ms 50560 KB Time limit exceeded
28 Execution timed out 2037 ms 73024 KB Time limit exceeded
29 Execution timed out 2055 ms 60820 KB Time limit exceeded
30 Execution timed out 2029 ms 60404 KB Time limit exceeded
31 Correct 1833 ms 38080 KB Output is correct
32 Correct 1925 ms 48924 KB Output is correct