# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
136945 |
2019-07-26T15:58:57 Z |
mlyean00 |
Race (IOI11_race) |
C++17 |
|
559 ms |
71288 KB |
#include "race.h"
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 200'000;
int n, k;
int ans = INT_MAX;
struct state {
int delta_k = 0;
int delta_v = 0;
map<int, int> min_n;
state() {
min_n[0] = 0;
}
void incr(int d) {
delta_k += d;
++delta_v;
auto it = min_n.find(k - delta_k);
if (it != min_n.end()) ans = min(ans, it->second + delta_v);
min_n.erase(min_n.upper_bound(k - delta_k), min_n.end());
}
void merge(state other) {
if (min_n.size() < other.min_n.size()) {
swap(delta_k, other.delta_k);
swap(delta_v, other.delta_v);
swap(min_n, other.min_n);
}
for (pair<int, int> const& p : other.min_n) {
int key, val;
tie(key, val) = p;
key += other.delta_k;
val += other.delta_v;
int rem = k - key;
auto it = min_n.find(rem - delta_k);
if (it != min_n.end()) {
ans = min(ans, val + it->second + delta_v);
}
}
for (pair<int, int> const& p : other.min_n) {
int key, val;
tie(key, val) = p;
key += other.delta_k;
val += other.delta_v;
auto it = min_n.find(key - delta_k);
if (it == min_n.end()) {
it = min_n.insert({key - delta_k, val - delta_v}).first;
} else if (val < it->second + delta_v) {
it->second = val - delta_v;
}
}
}
};
vector<int> g[MAX_N];
int parent[MAX_N];
int len[MAX_N];
void dfs1(int u) {
for (int v : g[u]) {
if (v == parent[u]) continue;
parent[v] = u;
dfs1(v);
}
}
state dfs2(int u) {
state st;
for (int v : g[u]) {
if (parent[v] == u) st.merge(dfs2(v));
}
st.incr(len[u]);
return st;
}
int best_path(int N, int K, int H[][2], int L[]) {
n = N, k = K;
for (int i = 0; i < n - 1; ++i) {
g[H[i][0]].push_back(H[i][1]);
g[H[i][1]].push_back(H[i][0]);
}
dfs1(0);
for (int i = 0; i < n - 1; ++i) {
if (parent[H[i][1]] == H[i][0]) swap(H[i][0], H[i][1]);
len[H[i][0]] = L[i];
}
dfs2(0);
return ans == INT_MAX ? -1 : ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4984 KB |
Output is correct |
2 |
Correct |
6 ms |
5112 KB |
Output is correct |
3 |
Correct |
6 ms |
5004 KB |
Output is correct |
4 |
Correct |
6 ms |
5028 KB |
Output is correct |
5 |
Correct |
6 ms |
4984 KB |
Output is correct |
6 |
Correct |
6 ms |
5112 KB |
Output is correct |
7 |
Correct |
6 ms |
5112 KB |
Output is correct |
8 |
Correct |
6 ms |
4984 KB |
Output is correct |
9 |
Correct |
6 ms |
5112 KB |
Output is correct |
10 |
Correct |
6 ms |
5112 KB |
Output is correct |
11 |
Correct |
6 ms |
5112 KB |
Output is correct |
12 |
Correct |
6 ms |
5112 KB |
Output is correct |
13 |
Correct |
6 ms |
5112 KB |
Output is correct |
14 |
Correct |
6 ms |
5112 KB |
Output is correct |
15 |
Correct |
6 ms |
5112 KB |
Output is correct |
16 |
Correct |
6 ms |
5112 KB |
Output is correct |
17 |
Correct |
6 ms |
5112 KB |
Output is correct |
18 |
Correct |
6 ms |
4984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4984 KB |
Output is correct |
2 |
Correct |
6 ms |
5112 KB |
Output is correct |
3 |
Correct |
6 ms |
5004 KB |
Output is correct |
4 |
Correct |
6 ms |
5028 KB |
Output is correct |
5 |
Correct |
6 ms |
4984 KB |
Output is correct |
6 |
Correct |
6 ms |
5112 KB |
Output is correct |
7 |
Correct |
6 ms |
5112 KB |
Output is correct |
8 |
Correct |
6 ms |
4984 KB |
Output is correct |
9 |
Correct |
6 ms |
5112 KB |
Output is correct |
10 |
Correct |
6 ms |
5112 KB |
Output is correct |
11 |
Correct |
6 ms |
5112 KB |
Output is correct |
12 |
Correct |
6 ms |
5112 KB |
Output is correct |
13 |
Correct |
6 ms |
5112 KB |
Output is correct |
14 |
Correct |
6 ms |
5112 KB |
Output is correct |
15 |
Correct |
6 ms |
5112 KB |
Output is correct |
16 |
Correct |
6 ms |
5112 KB |
Output is correct |
17 |
Correct |
6 ms |
5112 KB |
Output is correct |
18 |
Correct |
6 ms |
4984 KB |
Output is correct |
19 |
Correct |
6 ms |
5112 KB |
Output is correct |
20 |
Correct |
6 ms |
5112 KB |
Output is correct |
21 |
Correct |
7 ms |
5112 KB |
Output is correct |
22 |
Correct |
6 ms |
5112 KB |
Output is correct |
23 |
Correct |
7 ms |
5112 KB |
Output is correct |
24 |
Correct |
7 ms |
5112 KB |
Output is correct |
25 |
Correct |
7 ms |
5112 KB |
Output is correct |
26 |
Correct |
7 ms |
5112 KB |
Output is correct |
27 |
Correct |
7 ms |
5112 KB |
Output is correct |
28 |
Correct |
7 ms |
5112 KB |
Output is correct |
29 |
Correct |
7 ms |
5112 KB |
Output is correct |
30 |
Correct |
5 ms |
5112 KB |
Output is correct |
31 |
Correct |
7 ms |
5112 KB |
Output is correct |
32 |
Correct |
7 ms |
5112 KB |
Output is correct |
33 |
Correct |
8 ms |
5240 KB |
Output is correct |
34 |
Correct |
7 ms |
5112 KB |
Output is correct |
35 |
Correct |
7 ms |
5240 KB |
Output is correct |
36 |
Correct |
7 ms |
5240 KB |
Output is correct |
37 |
Correct |
7 ms |
5112 KB |
Output is correct |
38 |
Correct |
7 ms |
5112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4984 KB |
Output is correct |
2 |
Correct |
6 ms |
5112 KB |
Output is correct |
3 |
Correct |
6 ms |
5004 KB |
Output is correct |
4 |
Correct |
6 ms |
5028 KB |
Output is correct |
5 |
Correct |
6 ms |
4984 KB |
Output is correct |
6 |
Correct |
6 ms |
5112 KB |
Output is correct |
7 |
Correct |
6 ms |
5112 KB |
Output is correct |
8 |
Correct |
6 ms |
4984 KB |
Output is correct |
9 |
Correct |
6 ms |
5112 KB |
Output is correct |
10 |
Correct |
6 ms |
5112 KB |
Output is correct |
11 |
Correct |
6 ms |
5112 KB |
Output is correct |
12 |
Correct |
6 ms |
5112 KB |
Output is correct |
13 |
Correct |
6 ms |
5112 KB |
Output is correct |
14 |
Correct |
6 ms |
5112 KB |
Output is correct |
15 |
Correct |
6 ms |
5112 KB |
Output is correct |
16 |
Correct |
6 ms |
5112 KB |
Output is correct |
17 |
Correct |
6 ms |
5112 KB |
Output is correct |
18 |
Correct |
6 ms |
4984 KB |
Output is correct |
19 |
Correct |
126 ms |
10252 KB |
Output is correct |
20 |
Correct |
128 ms |
11684 KB |
Output is correct |
21 |
Correct |
124 ms |
11616 KB |
Output is correct |
22 |
Correct |
130 ms |
11768 KB |
Output is correct |
23 |
Correct |
104 ms |
11512 KB |
Output is correct |
24 |
Correct |
106 ms |
11844 KB |
Output is correct |
25 |
Correct |
116 ms |
25520 KB |
Output is correct |
26 |
Correct |
84 ms |
38136 KB |
Output is correct |
27 |
Correct |
224 ms |
19076 KB |
Output is correct |
28 |
Correct |
283 ms |
71288 KB |
Output is correct |
29 |
Correct |
289 ms |
67540 KB |
Output is correct |
30 |
Correct |
219 ms |
18936 KB |
Output is correct |
31 |
Correct |
217 ms |
18908 KB |
Output is correct |
32 |
Correct |
267 ms |
19064 KB |
Output is correct |
33 |
Correct |
271 ms |
19028 KB |
Output is correct |
34 |
Correct |
229 ms |
19832 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4984 KB |
Output is correct |
2 |
Correct |
6 ms |
5112 KB |
Output is correct |
3 |
Correct |
6 ms |
5004 KB |
Output is correct |
4 |
Correct |
6 ms |
5028 KB |
Output is correct |
5 |
Correct |
6 ms |
4984 KB |
Output is correct |
6 |
Correct |
6 ms |
5112 KB |
Output is correct |
7 |
Correct |
6 ms |
5112 KB |
Output is correct |
8 |
Correct |
6 ms |
4984 KB |
Output is correct |
9 |
Correct |
6 ms |
5112 KB |
Output is correct |
10 |
Correct |
6 ms |
5112 KB |
Output is correct |
11 |
Correct |
6 ms |
5112 KB |
Output is correct |
12 |
Correct |
6 ms |
5112 KB |
Output is correct |
13 |
Correct |
6 ms |
5112 KB |
Output is correct |
14 |
Correct |
6 ms |
5112 KB |
Output is correct |
15 |
Correct |
6 ms |
5112 KB |
Output is correct |
16 |
Correct |
6 ms |
5112 KB |
Output is correct |
17 |
Correct |
6 ms |
5112 KB |
Output is correct |
18 |
Correct |
6 ms |
4984 KB |
Output is correct |
19 |
Correct |
6 ms |
5112 KB |
Output is correct |
20 |
Correct |
6 ms |
5112 KB |
Output is correct |
21 |
Correct |
7 ms |
5112 KB |
Output is correct |
22 |
Correct |
6 ms |
5112 KB |
Output is correct |
23 |
Correct |
7 ms |
5112 KB |
Output is correct |
24 |
Correct |
7 ms |
5112 KB |
Output is correct |
25 |
Correct |
7 ms |
5112 KB |
Output is correct |
26 |
Correct |
7 ms |
5112 KB |
Output is correct |
27 |
Correct |
7 ms |
5112 KB |
Output is correct |
28 |
Correct |
7 ms |
5112 KB |
Output is correct |
29 |
Correct |
7 ms |
5112 KB |
Output is correct |
30 |
Correct |
5 ms |
5112 KB |
Output is correct |
31 |
Correct |
7 ms |
5112 KB |
Output is correct |
32 |
Correct |
7 ms |
5112 KB |
Output is correct |
33 |
Correct |
8 ms |
5240 KB |
Output is correct |
34 |
Correct |
7 ms |
5112 KB |
Output is correct |
35 |
Correct |
7 ms |
5240 KB |
Output is correct |
36 |
Correct |
7 ms |
5240 KB |
Output is correct |
37 |
Correct |
7 ms |
5112 KB |
Output is correct |
38 |
Correct |
7 ms |
5112 KB |
Output is correct |
39 |
Correct |
126 ms |
10252 KB |
Output is correct |
40 |
Correct |
128 ms |
11684 KB |
Output is correct |
41 |
Correct |
124 ms |
11616 KB |
Output is correct |
42 |
Correct |
130 ms |
11768 KB |
Output is correct |
43 |
Correct |
104 ms |
11512 KB |
Output is correct |
44 |
Correct |
106 ms |
11844 KB |
Output is correct |
45 |
Correct |
116 ms |
25520 KB |
Output is correct |
46 |
Correct |
84 ms |
38136 KB |
Output is correct |
47 |
Correct |
224 ms |
19076 KB |
Output is correct |
48 |
Correct |
283 ms |
71288 KB |
Output is correct |
49 |
Correct |
289 ms |
67540 KB |
Output is correct |
50 |
Correct |
219 ms |
18936 KB |
Output is correct |
51 |
Correct |
217 ms |
18908 KB |
Output is correct |
52 |
Correct |
267 ms |
19064 KB |
Output is correct |
53 |
Correct |
271 ms |
19028 KB |
Output is correct |
54 |
Correct |
229 ms |
19832 KB |
Output is correct |
55 |
Correct |
25 ms |
5880 KB |
Output is correct |
56 |
Correct |
14 ms |
5728 KB |
Output is correct |
57 |
Correct |
73 ms |
11520 KB |
Output is correct |
58 |
Correct |
56 ms |
11548 KB |
Output is correct |
59 |
Correct |
131 ms |
38292 KB |
Output is correct |
60 |
Correct |
381 ms |
69212 KB |
Output is correct |
61 |
Correct |
246 ms |
19320 KB |
Output is correct |
62 |
Correct |
268 ms |
19220 KB |
Output is correct |
63 |
Correct |
301 ms |
19320 KB |
Output is correct |
64 |
Correct |
559 ms |
25464 KB |
Output is correct |
65 |
Correct |
249 ms |
19452 KB |
Output is correct |
66 |
Correct |
307 ms |
58744 KB |
Output is correct |
67 |
Correct |
192 ms |
19572 KB |
Output is correct |
68 |
Correct |
420 ms |
23136 KB |
Output is correct |
69 |
Correct |
434 ms |
26368 KB |
Output is correct |
70 |
Correct |
414 ms |
22520 KB |
Output is correct |