# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1075417 |
2024-08-26T05:47:19 Z |
juicy |
Race (IOI11_race) |
C++17 |
|
301 ms |
88656 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);
}
}
map<long long, int>().swap(mp[v]);
}
}
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 |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 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 |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 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 |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 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 |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
604 KB |
Output is correct |
23 |
Correct |
1 ms |
604 KB |
Output is correct |
24 |
Correct |
2 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 |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
604 KB |
Output is correct |
29 |
Correct |
1 ms |
604 KB |
Output is correct |
30 |
Correct |
1 ms |
604 KB |
Output is correct |
31 |
Correct |
1 ms |
604 KB |
Output is correct |
32 |
Correct |
1 ms |
576 KB |
Output is correct |
33 |
Correct |
1 ms |
604 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 |
600 KB |
Output is correct |
37 |
Correct |
1 ms |
604 KB |
Output is correct |
38 |
Correct |
1 ms |
600 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 |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 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 |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
69 ms |
12376 KB |
Output is correct |
20 |
Correct |
64 ms |
12376 KB |
Output is correct |
21 |
Correct |
60 ms |
12380 KB |
Output is correct |
22 |
Correct |
61 ms |
12368 KB |
Output is correct |
23 |
Correct |
107 ms |
12628 KB |
Output is correct |
24 |
Correct |
72 ms |
12512 KB |
Output is correct |
25 |
Correct |
64 ms |
28408 KB |
Output is correct |
26 |
Correct |
53 ms |
44368 KB |
Output is correct |
27 |
Correct |
118 ms |
27520 KB |
Output is correct |
28 |
Correct |
220 ms |
88656 KB |
Output is correct |
29 |
Correct |
221 ms |
85844 KB |
Output is correct |
30 |
Correct |
119 ms |
27404 KB |
Output is correct |
31 |
Correct |
129 ms |
27464 KB |
Output is correct |
32 |
Correct |
137 ms |
27968 KB |
Output is correct |
33 |
Correct |
137 ms |
27220 KB |
Output is correct |
34 |
Correct |
229 ms |
40532 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 |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 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 |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
604 KB |
Output is correct |
23 |
Correct |
1 ms |
604 KB |
Output is correct |
24 |
Correct |
2 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 |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
604 KB |
Output is correct |
29 |
Correct |
1 ms |
604 KB |
Output is correct |
30 |
Correct |
1 ms |
604 KB |
Output is correct |
31 |
Correct |
1 ms |
604 KB |
Output is correct |
32 |
Correct |
1 ms |
576 KB |
Output is correct |
33 |
Correct |
1 ms |
604 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 |
600 KB |
Output is correct |
37 |
Correct |
1 ms |
604 KB |
Output is correct |
38 |
Correct |
1 ms |
600 KB |
Output is correct |
39 |
Correct |
69 ms |
12376 KB |
Output is correct |
40 |
Correct |
64 ms |
12376 KB |
Output is correct |
41 |
Correct |
60 ms |
12380 KB |
Output is correct |
42 |
Correct |
61 ms |
12368 KB |
Output is correct |
43 |
Correct |
107 ms |
12628 KB |
Output is correct |
44 |
Correct |
72 ms |
12512 KB |
Output is correct |
45 |
Correct |
64 ms |
28408 KB |
Output is correct |
46 |
Correct |
53 ms |
44368 KB |
Output is correct |
47 |
Correct |
118 ms |
27520 KB |
Output is correct |
48 |
Correct |
220 ms |
88656 KB |
Output is correct |
49 |
Correct |
221 ms |
85844 KB |
Output is correct |
50 |
Correct |
119 ms |
27404 KB |
Output is correct |
51 |
Correct |
129 ms |
27464 KB |
Output is correct |
52 |
Correct |
137 ms |
27968 KB |
Output is correct |
53 |
Correct |
137 ms |
27220 KB |
Output is correct |
54 |
Correct |
229 ms |
40532 KB |
Output is correct |
55 |
Correct |
10 ms |
2140 KB |
Output is correct |
56 |
Correct |
5 ms |
1772 KB |
Output is correct |
57 |
Correct |
37 ms |
13916 KB |
Output is correct |
58 |
Correct |
32 ms |
13512 KB |
Output is correct |
59 |
Correct |
74 ms |
44372 KB |
Output is correct |
60 |
Correct |
212 ms |
86724 KB |
Output is correct |
61 |
Correct |
141 ms |
29264 KB |
Output is correct |
62 |
Correct |
116 ms |
27640 KB |
Output is correct |
63 |
Correct |
125 ms |
27808 KB |
Output is correct |
64 |
Correct |
301 ms |
36156 KB |
Output is correct |
65 |
Correct |
295 ms |
40792 KB |
Output is correct |
66 |
Correct |
216 ms |
79696 KB |
Output is correct |
67 |
Correct |
91 ms |
28096 KB |
Output is correct |
68 |
Correct |
216 ms |
38500 KB |
Output is correct |
69 |
Correct |
239 ms |
43348 KB |
Output is correct |
70 |
Correct |
200 ms |
37200 KB |
Output is correct |