답안 #867724

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
867724 2023-10-29T10:21:56 Z BoopyTheNoob Tracks in the Snow (BOI13_tracks) C++14
84.6875 / 100
2000 ms 743656 KB
#include <iostream>
#include <vector>
#include <deque>
using namespace std;

int main (void) {
    iostream::sync_with_stdio(false);
	cin.tie(0);
    int dx[4] = {0, 0, 1, -1};
    int dy[4] = {1, -1, 0, 0};
    int N, M;
    cin >> N >> M;
    //vector<string> grid(N);
    string grid[4000];
    for (int i = 0; i < N; i++)
        cin >> grid[i];
    vector<vector<int>> dist(N, vector<int>(M, 1e9));
    deque<vector<int>> bfs;
    bfs.push_back({0, 0, 1});
    int ans = 0;
    while (!bfs.empty()) {
        int x = bfs.front()[0], y = bfs.front()[1], d = bfs.front()[2];
        bfs.pop_front();
        dist[x][y] = d;
        ans = max(ans, d);
        for (int i = 0; i < 4; i++) {
            int nx = x + dx[i], ny = y + dy[i];
            if (nx < 0 || nx >= N || ny < 0 || ny >= M)
                continue;
            if (dist[nx][ny] < 1e9 || grid[nx][ny] == '.')
                continue;
            vector<int> next = {nx, ny, d};
            if (grid[x][y] != grid[nx][ny]) {
                next[2]++;
                bfs.push_back(next);
            } else
                bfs.push_front(next);
        }
    }
    /*for (auto x: dist) {
        for (auto y: x) {
            cout << y << " ";
        }
        cout << endl;
    }*/
    cout << ans << endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 2908 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 19 ms 4188 KB Output is correct
5 Correct 3 ms 860 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 600 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 3 ms 860 KB Output is correct
11 Correct 5 ms 1628 KB Output is correct
12 Correct 12 ms 1368 KB Output is correct
13 Correct 2 ms 860 KB Output is correct
14 Correct 3 ms 860 KB Output is correct
15 Correct 25 ms 2136 KB Output is correct
16 Correct 38 ms 2920 KB Output is correct
17 Correct 14 ms 1884 KB Output is correct
18 Correct 19 ms 4188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 856 KB Output is correct
2 Correct 79 ms 8588 KB Output is correct
3 Correct 342 ms 80980 KB Output is correct
4 Correct 70 ms 19344 KB Output is correct
5 Correct 188 ms 45624 KB Output is correct
6 Execution timed out 2017 ms 298728 KB Time limit exceeded
7 Correct 1 ms 860 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 5 ms 1368 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 860 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 80 ms 8540 KB Output is correct
14 Correct 44 ms 5212 KB Output is correct
15 Correct 15 ms 5468 KB Output is correct
16 Correct 44 ms 3932 KB Output is correct
17 Correct 203 ms 21084 KB Output is correct
18 Correct 78 ms 20524 KB Output is correct
19 Correct 66 ms 19344 KB Output is correct
20 Correct 84 ms 17752 KB Output is correct
21 Correct 202 ms 47196 KB Output is correct
22 Correct 195 ms 45648 KB Output is correct
23 Correct 413 ms 39772 KB Output is correct
24 Correct 153 ms 45856 KB Output is correct
25 Correct 421 ms 81016 KB Output is correct
26 Execution timed out 2081 ms 743656 KB Time limit exceeded
27 Execution timed out 2060 ms 389692 KB Time limit exceeded
28 Execution timed out 2101 ms 305364 KB Time limit exceeded
29 Execution timed out 2023 ms 288060 KB Time limit exceeded
30 Execution timed out 2120 ms 336416 KB Time limit exceeded
31 Correct 1729 ms 65284 KB Output is correct
32 Execution timed out 2036 ms 358056 KB Time limit exceeded