답안 #450046

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
450046 2021-08-02T10:56:10 Z four_specks Tracks in the Snow (BOI13_tracks) C++17
100 / 100
1122 ms 152436 KB
#include <bits/stdc++.h>

using namespace std;

void solve()
{
    int h, w;
    cin >> h >> w;

    vector<vector<int>> grid(h, vector<int>(w));
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            char c;
            cin >> c;

            if (c == '.')
                grid[i][j] = 0;
            else if (c == 'R')
                grid[i][j] = 1;
            else if (c == 'F')
                grid[i][j] = 2;
        }
    }

    int n = 0;

    vector<vector<int>> d(h, vector<int>(w, 0));
    deque<pair<int, int>> dq;
    for (dq.emplace_front(0, 0), d[0][0] = 1; !dq.empty();)
    {
        auto [y, x] = dq.front();
        dq.pop_front();
        n = max(n, d[y][x]);
        for (auto [dx, dy] : {pair(0, -1), pair(0, 1), pair(-1, 0), pair(1, 0)})
        {
            if (x + dx >= 0 && x + dx < w && y + dy >= 0 && y + dy < h)
            {
                if (grid[y + dy][x + dx] && d[y + dy][x + dx] == 0)
                {
                    if (grid[y + dy][x + dx] == grid[y][x])
                    {
                        d[y + dy][x + dx] = d[y][x];
                        dq.emplace_front(y + dy, x + dx);
                    }
                    else
                    {
                        d[y + dy][x + dx] = d[y][x] + 1;
                        dq.emplace_back(y + dy, x + dx);
                    }
                }
            }
        }
    }

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

int main()
{
    ios_base::sync_with_stdio(false), cin.tie(NULL);

    solve();

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 2480 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 8 ms 1868 KB Output is correct
5 Correct 4 ms 972 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 3 ms 844 KB Output is correct
11 Correct 3 ms 716 KB Output is correct
12 Correct 6 ms 1140 KB Output is correct
13 Correct 5 ms 972 KB Output is correct
14 Correct 4 ms 972 KB Output is correct
15 Correct 17 ms 2584 KB Output is correct
16 Correct 16 ms 2528 KB Output is correct
17 Correct 13 ms 2456 KB Output is correct
18 Correct 9 ms 1924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 972 KB Output is correct
2 Correct 80 ms 14124 KB Output is correct
3 Correct 538 ms 132216 KB Output is correct
4 Correct 136 ms 33464 KB Output is correct
5 Correct 294 ms 76884 KB Output is correct
6 Correct 993 ms 145488 KB Output is correct
7 Correct 3 ms 972 KB Output is correct
8 Correct 3 ms 972 KB Output is correct
9 Correct 3 ms 740 KB Output is correct
10 Correct 2 ms 588 KB Output is correct
11 Correct 3 ms 972 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 69 ms 14128 KB Output is correct
14 Correct 44 ms 8308 KB Output is correct
15 Correct 39 ms 9116 KB Output is correct
16 Correct 31 ms 5896 KB Output is correct
17 Correct 231 ms 36164 KB Output is correct
18 Correct 169 ms 35604 KB Output is correct
19 Correct 157 ms 33476 KB Output is correct
20 Correct 113 ms 30724 KB Output is correct
21 Correct 300 ms 79664 KB Output is correct
22 Correct 294 ms 76888 KB Output is correct
23 Correct 372 ms 65784 KB Output is correct
24 Correct 300 ms 77656 KB Output is correct
25 Correct 895 ms 132248 KB Output is correct
26 Correct 571 ms 152436 KB Output is correct
27 Correct 796 ms 148704 KB Output is correct
28 Correct 1122 ms 144344 KB Output is correct
29 Correct 965 ms 144688 KB Output is correct
30 Correct 971 ms 143300 KB Output is correct
31 Correct 835 ms 86808 KB Output is correct
32 Correct 800 ms 146660 KB Output is correct