Submission #1075418

# Submission time Handle Problem Language Result Execution time Memory
1075418 2024-08-26T05:47:47 Z juicy Race (IOI11_race) C++17
100 / 100
395 ms 98060 KB
#include "race.h"

#include <bits/stdc++.h>

using namespace std;

int best_path(int n, int k, int H[][2], int L[]) {
    vector<vector<array<int, 2>>> g(n);
    for (int i = 0; i < n; ++i) {
        for (auto it : {0, 1}) {
            g[H[i][it]].push_back({H[i][it ^ 1], i});
        }
    }
    vector<map<long long, int>> mp(n);
    function<int(int, int, int, long long)> dfs = [&](int u, int p, int h, long long dep) {
        int res = n + 1;
        mp[u][dep] = h;
        for (auto [v, ind] : g[u]) {
            if (v != p) {
                res = min(res, dfs(v, u, h + 1, dep + L[ind]));
                if (mp[u].size() < mp[v].size()) {
                    mp[u].swap(mp[v]);
                }
                for (auto [x, y] : mp[v]) {
                    if (mp[u].count(k + 2 * dep - x)) {
                        res = min(res, y + mp[u][k + 2 * dep - x] - 2 * h);
                    }
                }
                for (auto [x, y] : mp[v]) {
                    if (!mp[u].count(x)) {
                        mp[u][x] = y;
                    } else {
                        mp[u][x] = min(mp[u][x], y);
                    }
                }
            }
        }
        return res;
    };
    auto res = dfs(0, 0, 0, 0);
    return res == n + 1 ? -1 : res;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 2 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 1 ms 712 KB Output is correct
34 Correct 1 ms 604 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 1 ms 604 KB Output is correct
37 Correct 1 ms 604 KB Output is correct
38 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 97 ms 27732 KB Output is correct
20 Correct 101 ms 27936 KB Output is correct
21 Correct 93 ms 27452 KB Output is correct
22 Correct 87 ms 27244 KB Output is correct
23 Correct 130 ms 39760 KB Output is correct
24 Correct 93 ms 30548 KB Output is correct
25 Correct 74 ms 30144 KB Output is correct
26 Correct 48 ms 39764 KB Output is correct
27 Correct 140 ms 43344 KB Output is correct
28 Correct 230 ms 91728 KB Output is correct
29 Correct 244 ms 89428 KB Output is correct
30 Correct 141 ms 43348 KB Output is correct
31 Correct 145 ms 43348 KB Output is correct
32 Correct 164 ms 43552 KB Output is correct
33 Correct 184 ms 48464 KB Output is correct
34 Correct 309 ms 80300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 2 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 1 ms 712 KB Output is correct
34 Correct 1 ms 604 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 1 ms 604 KB Output is correct
37 Correct 1 ms 604 KB Output is correct
38 Correct 1 ms 604 KB Output is correct
39 Correct 97 ms 27732 KB Output is correct
40 Correct 101 ms 27936 KB Output is correct
41 Correct 93 ms 27452 KB Output is correct
42 Correct 87 ms 27244 KB Output is correct
43 Correct 130 ms 39760 KB Output is correct
44 Correct 93 ms 30548 KB Output is correct
45 Correct 74 ms 30144 KB Output is correct
46 Correct 48 ms 39764 KB Output is correct
47 Correct 140 ms 43344 KB Output is correct
48 Correct 230 ms 91728 KB Output is correct
49 Correct 244 ms 89428 KB Output is correct
50 Correct 141 ms 43348 KB Output is correct
51 Correct 145 ms 43348 KB Output is correct
52 Correct 164 ms 43552 KB Output is correct
53 Correct 184 ms 48464 KB Output is correct
54 Correct 309 ms 80300 KB Output is correct
55 Correct 11 ms 4184 KB Output is correct
56 Correct 5 ms 2908 KB Output is correct
57 Correct 55 ms 25092 KB Output is correct
58 Correct 36 ms 18640 KB Output is correct
59 Correct 74 ms 46204 KB Output is correct
60 Correct 216 ms 90192 KB Output is correct
61 Correct 164 ms 46768 KB Output is correct
62 Correct 135 ms 43344 KB Output is correct
63 Correct 162 ms 43512 KB Output is correct
64 Correct 395 ms 98060 KB Output is correct
65 Correct 391 ms 95824 KB Output is correct
66 Correct 240 ms 84308 KB Output is correct
67 Correct 131 ms 37348 KB Output is correct
68 Correct 262 ms 59472 KB Output is correct
69 Correct 286 ms 64592 KB Output is correct
70 Correct 246 ms 57188 KB Output is correct