답안 #459602

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
459602 2021-08-08T18:09:37 Z chuangsheep Tracks in the Snow (BOI13_tracks) C++11
100 / 100
793 ms 124376 KB
#include <bits/stdc++.h>
using namespace std;

#define all(x) begin(x), end(x)
#define allr(x, r) begin(x), begin(x) + (r)
#define mp make_pair

using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;

int xs[]{0, 1, 0, -1}, ys[]{-1, 0, 1, 0};

int main()
{
#if defined(DEBUG) && !defined(ONLINE_JUDGE)
    // DEBUG
    cerr << "DEBUG flag set - see test.out for output\n";
    freopen("/home/chuang/shared-drives/F:/repos/cp/ois/boi13/test.in", "r", stdin);
    freopen("/home/chuang/shared-drives/F:/repos/cp/ois/boi13/test.out", "w", stdout);
#else
    cin.tie(0)->sync_with_stdio(false);
#endif

    int H, W;
    cin >> H >> W;
    vector<vi> dist(H);
    for (auto &r : dist)
        r.assign(W, 0);
    dist[0][0] = 1;

    vector<string> grid(H);
    for (auto &r : grid)
        cin >> r;

    deque<pi> bfs;
    bfs.push_back(mp(0, 0));
    int ans = 1;
    while (!bfs.empty())
    {
        pi cell = bfs.front();
        bfs.pop_front();
        ans = max(ans, dist[cell.first][cell.second]);
        for (int i = 0; i < 4; i++)
        {
            int r = cell.first + xs[i];
            int c = cell.second + ys[i];
            if (r >= 0 && r < H && c >= 0 && c < W && grid[r][c] != '.' && dist[r][c] == 0)
            {
                if (grid[cell.first][cell.second] == grid[r][c])
                {
                    dist[r][c] = dist[cell.first][cell.second];
                    bfs.push_front(mp(r, c));
                }
                else
                {
                    dist[r][c] = dist[cell.first][cell.second] + 1;
                    bfs.push_back(mp(r, c));
                }
            }
        }
    }

    cout << ans << endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 1740 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 6 ms 1484 KB Output is correct
5 Correct 2 ms 716 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 2 ms 716 KB Output is correct
11 Correct 2 ms 588 KB Output is correct
12 Correct 4 ms 844 KB Output is correct
13 Correct 2 ms 716 KB Output is correct
14 Correct 2 ms 716 KB Output is correct
15 Correct 10 ms 1868 KB Output is correct
16 Correct 11 ms 1828 KB Output is correct
17 Correct 7 ms 1740 KB Output is correct
18 Correct 6 ms 1488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 708 KB Output is correct
2 Correct 36 ms 9676 KB Output is correct
3 Correct 194 ms 96500 KB Output is correct
4 Correct 56 ms 22728 KB Output is correct
5 Correct 152 ms 54288 KB Output is correct
6 Correct 704 ms 110940 KB Output is correct
7 Correct 2 ms 716 KB Output is correct
8 Correct 2 ms 716 KB Output is correct
9 Correct 2 ms 588 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 2 ms 716 KB Output is correct
12 Correct 1 ms 456 KB Output is correct
13 Correct 36 ms 9676 KB Output is correct
14 Correct 24 ms 5708 KB Output is correct
15 Correct 15 ms 6220 KB Output is correct
16 Correct 20 ms 4176 KB Output is correct
17 Correct 104 ms 24516 KB Output is correct
18 Correct 66 ms 24140 KB Output is correct
19 Correct 55 ms 22732 KB Output is correct
20 Correct 47 ms 20812 KB Output is correct
21 Correct 117 ms 56068 KB Output is correct
22 Correct 150 ms 54272 KB Output is correct
23 Correct 195 ms 46752 KB Output is correct
24 Correct 140 ms 54660 KB Output is correct
25 Correct 414 ms 96544 KB Output is correct
26 Correct 793 ms 124048 KB Output is correct
27 Correct 671 ms 124376 KB Output is correct
28 Correct 688 ms 111000 KB Output is correct
29 Correct 671 ms 109012 KB Output is correct
30 Correct 680 ms 114268 KB Output is correct
31 Correct 500 ms 62280 KB Output is correct
32 Correct 654 ms 119196 KB Output is correct