# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
933544 |
2024-02-25T21:32:41 Z |
Maaxle |
Race (IOI11_race) |
C++17 |
|
390 ms |
104020 KB |
#include "race.h"
#include <bits/stdc++.h>
#define range(it, a, b) for (ll it = a; it < b; it++)
#define all(x) begin(x), end(x)
#define ll long long
#define ull unsigned long long
#define INF64 ((ll) 1 << 60)
#define INF32 (1 << 30)
#define mset multiset
#define uset unordered_set
#define umap unordered_map
#define pqueue priority_queue
#define ptr(A) shared_ptr<A>
using namespace std;
struct Path {
ll i, w;
};
ll n, k;
vector<vector<Path>> adj;
vector<map<ll, ll>> paths;
ll ans = INF64;
void debug (ll i) {
cout << "NODE: " << i << '\n';
for (auto child_path : paths[i])
cout << child_path.first << " : " << child_path.second << '\n';
}
void explore(ll i, ll from, ll cnt, ll roads) {
paths[i][cnt] = roads;
for (Path child : adj[i]) {
if (child.i == from)
continue;
explore(child.i, i, cnt + child.w, roads + 1);
if (paths[i].size() < paths[child.i].size())
swap(paths[child.i], paths[i]);
for (auto child_path : paths[child.i]) {
ll sum = k + 2*cnt;
if (paths[i].count(sum - child_path.first))
ans = min(ans, paths[i][sum - child_path.first] + child_path.second - 2*roads);
}
for (auto child_path : paths[child.i]) {
if (paths[i].count(child_path.first))
paths[i][child_path.first] = min(paths[i][child_path.first], child_path.second);
else
paths[i][child_path.first] = child_path.second;
}
}
// debug(i);
}
int best_path(int N, int K, int H[][2], int L[]) {
n = N; k = K;
adj.resize(n);
paths.resize(n);
range(i, 0, n) {
adj[H[i][0]].push_back({H[i][1], L[i]});
adj[H[i][1]].push_back({H[i][0], L[i]});
}
explore(0, 0, 0, 0);
return (ans == INF64 ? -1 : ans);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2480 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
1 ms |
2548 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2480 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
1 ms |
2548 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2652 KB |
Output is correct |
22 |
Correct |
1 ms |
2652 KB |
Output is correct |
23 |
Correct |
1 ms |
2904 KB |
Output is correct |
24 |
Correct |
2 ms |
2652 KB |
Output is correct |
25 |
Correct |
2 ms |
2652 KB |
Output is correct |
26 |
Correct |
2 ms |
2648 KB |
Output is correct |
27 |
Correct |
1 ms |
2648 KB |
Output is correct |
28 |
Correct |
2 ms |
2748 KB |
Output is correct |
29 |
Correct |
2 ms |
2648 KB |
Output is correct |
30 |
Correct |
2 ms |
2652 KB |
Output is correct |
31 |
Correct |
1 ms |
2652 KB |
Output is correct |
32 |
Correct |
1 ms |
2652 KB |
Output is correct |
33 |
Correct |
2 ms |
2652 KB |
Output is correct |
34 |
Correct |
1 ms |
2652 KB |
Output is correct |
35 |
Correct |
1 ms |
2652 KB |
Output is correct |
36 |
Correct |
1 ms |
2652 KB |
Output is correct |
37 |
Correct |
1 ms |
2652 KB |
Output is correct |
38 |
Correct |
1 ms |
2644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2480 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
1 ms |
2548 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
99 ms |
32360 KB |
Output is correct |
20 |
Correct |
89 ms |
33364 KB |
Output is correct |
21 |
Correct |
88 ms |
32784 KB |
Output is correct |
22 |
Correct |
88 ms |
32932 KB |
Output is correct |
23 |
Correct |
132 ms |
45904 KB |
Output is correct |
24 |
Correct |
99 ms |
35884 KB |
Output is correct |
25 |
Correct |
84 ms |
35924 KB |
Output is correct |
26 |
Correct |
52 ms |
45332 KB |
Output is correct |
27 |
Correct |
150 ms |
50004 KB |
Output is correct |
28 |
Correct |
282 ms |
98676 KB |
Output is correct |
29 |
Correct |
265 ms |
96648 KB |
Output is correct |
30 |
Correct |
147 ms |
50512 KB |
Output is correct |
31 |
Correct |
148 ms |
50768 KB |
Output is correct |
32 |
Correct |
222 ms |
50508 KB |
Output is correct |
33 |
Correct |
182 ms |
55728 KB |
Output is correct |
34 |
Correct |
275 ms |
87892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2480 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
1 ms |
2548 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2652 KB |
Output is correct |
22 |
Correct |
1 ms |
2652 KB |
Output is correct |
23 |
Correct |
1 ms |
2904 KB |
Output is correct |
24 |
Correct |
2 ms |
2652 KB |
Output is correct |
25 |
Correct |
2 ms |
2652 KB |
Output is correct |
26 |
Correct |
2 ms |
2648 KB |
Output is correct |
27 |
Correct |
1 ms |
2648 KB |
Output is correct |
28 |
Correct |
2 ms |
2748 KB |
Output is correct |
29 |
Correct |
2 ms |
2648 KB |
Output is correct |
30 |
Correct |
2 ms |
2652 KB |
Output is correct |
31 |
Correct |
1 ms |
2652 KB |
Output is correct |
32 |
Correct |
1 ms |
2652 KB |
Output is correct |
33 |
Correct |
2 ms |
2652 KB |
Output is correct |
34 |
Correct |
1 ms |
2652 KB |
Output is correct |
35 |
Correct |
1 ms |
2652 KB |
Output is correct |
36 |
Correct |
1 ms |
2652 KB |
Output is correct |
37 |
Correct |
1 ms |
2652 KB |
Output is correct |
38 |
Correct |
1 ms |
2644 KB |
Output is correct |
39 |
Correct |
99 ms |
32360 KB |
Output is correct |
40 |
Correct |
89 ms |
33364 KB |
Output is correct |
41 |
Correct |
88 ms |
32784 KB |
Output is correct |
42 |
Correct |
88 ms |
32932 KB |
Output is correct |
43 |
Correct |
132 ms |
45904 KB |
Output is correct |
44 |
Correct |
99 ms |
35884 KB |
Output is correct |
45 |
Correct |
84 ms |
35924 KB |
Output is correct |
46 |
Correct |
52 ms |
45332 KB |
Output is correct |
47 |
Correct |
150 ms |
50004 KB |
Output is correct |
48 |
Correct |
282 ms |
98676 KB |
Output is correct |
49 |
Correct |
265 ms |
96648 KB |
Output is correct |
50 |
Correct |
147 ms |
50512 KB |
Output is correct |
51 |
Correct |
148 ms |
50768 KB |
Output is correct |
52 |
Correct |
222 ms |
50508 KB |
Output is correct |
53 |
Correct |
182 ms |
55728 KB |
Output is correct |
54 |
Correct |
275 ms |
87892 KB |
Output is correct |
55 |
Correct |
11 ms |
6376 KB |
Output is correct |
56 |
Correct |
6 ms |
4956 KB |
Output is correct |
57 |
Correct |
59 ms |
30168 KB |
Output is correct |
58 |
Correct |
42 ms |
23688 KB |
Output is correct |
59 |
Correct |
83 ms |
51648 KB |
Output is correct |
60 |
Correct |
253 ms |
97256 KB |
Output is correct |
61 |
Correct |
180 ms |
53332 KB |
Output is correct |
62 |
Correct |
150 ms |
50552 KB |
Output is correct |
63 |
Correct |
200 ms |
50592 KB |
Output is correct |
64 |
Correct |
390 ms |
104020 KB |
Output is correct |
65 |
Correct |
390 ms |
103764 KB |
Output is correct |
66 |
Correct |
281 ms |
89424 KB |
Output is correct |
67 |
Correct |
129 ms |
45248 KB |
Output is correct |
68 |
Correct |
293 ms |
66384 KB |
Output is correct |
69 |
Correct |
327 ms |
69204 KB |
Output is correct |
70 |
Correct |
276 ms |
64248 KB |
Output is correct |