# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
241634 |
2020-06-24T21:32:41 Z |
johutha |
Race (IOI11_race) |
C++17 |
|
488 ms |
106372 KB |
#include "race.h"
#include <iostream>
#include <vector>
#include <map>
#define int int64_t
using namespace std;
struct coll
{
map<int,int>* mp = new map<int,int>();
int offs = 0;
bool operator<(const coll& c2)
{
return mp->size() < c2.mp->size();
}
void insert(int id, int v)
{
id -= offs;
if (mp->find(id) != mp->end()) mp->at(id) = min(v, mp->at(id));
else mp->insert(make_pair(id, v));
}
int query(int k)
{
k -= offs;
if (mp->find(k) == mp->end()) return 1e7;
return mp->at(k);
}
static int check(coll bs, coll nw, int k, int d)
{
if (bs < nw) swap(bs, nw);
int mn = 1e7;
for (auto p : (*nw.mp))
{
int ck = p.first + nw.offs;
if (k < ck) continue;
mn = min(mn, bs.query(k - ck) + p.second - 2*d);
}
return mn;
}
static coll merge(coll bs, coll nw)
{
if (bs < nw) swap(bs, nw);
for (auto p : (*nw.mp))
{
bs.insert(p.first + nw.offs, p.second);
}
return bs;
}
};
struct tree
{
int n, k;
vector<vector<pair<int,int>>> adjlist;
int res = 1e7;
coll dfs(int curr, int par, int d)
{
coll rt = coll();
rt.insert(0, d);
for (auto p : adjlist[curr])
{
if (p.first == par) continue;
coll nt = dfs(p.first, curr, d + 1);
nt.offs += p.second;
res = min(res, coll::check(nt, rt, k, d));
rt = coll::merge(nt, rt);
}
return rt;
}
};
signed best_path(signed N, signed K, signed H[][2], signed L[])
{
tree t;
t.n = N;
t.k = K;
t.adjlist.resize(N);
for (int i = 0; i < N - 1; i++)
{
t.adjlist[H[i][0]].emplace_back(H[i][1], L[i]);
t.adjlist[H[i][1]].emplace_back(H[i][0], L[i]);
}
t.dfs(0, -1, 0);
return (t.res >= N ? -1 : t.res);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
512 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
512 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
4 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
6 ms |
640 KB |
Output is correct |
22 |
Correct |
6 ms |
768 KB |
Output is correct |
23 |
Correct |
6 ms |
768 KB |
Output is correct |
24 |
Correct |
6 ms |
768 KB |
Output is correct |
25 |
Correct |
6 ms |
768 KB |
Output is correct |
26 |
Correct |
6 ms |
896 KB |
Output is correct |
27 |
Correct |
5 ms |
640 KB |
Output is correct |
28 |
Correct |
6 ms |
768 KB |
Output is correct |
29 |
Correct |
6 ms |
768 KB |
Output is correct |
30 |
Correct |
6 ms |
768 KB |
Output is correct |
31 |
Correct |
6 ms |
768 KB |
Output is correct |
32 |
Correct |
6 ms |
768 KB |
Output is correct |
33 |
Correct |
6 ms |
768 KB |
Output is correct |
34 |
Correct |
6 ms |
640 KB |
Output is correct |
35 |
Correct |
5 ms |
640 KB |
Output is correct |
36 |
Correct |
5 ms |
640 KB |
Output is correct |
37 |
Correct |
6 ms |
640 KB |
Output is correct |
38 |
Correct |
6 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
512 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
135 ms |
32248 KB |
Output is correct |
20 |
Correct |
133 ms |
32248 KB |
Output is correct |
21 |
Correct |
129 ms |
31864 KB |
Output is correct |
22 |
Correct |
139 ms |
31480 KB |
Output is correct |
23 |
Correct |
161 ms |
44408 KB |
Output is correct |
24 |
Correct |
131 ms |
34424 KB |
Output is correct |
25 |
Correct |
112 ms |
33784 KB |
Output is correct |
26 |
Correct |
82 ms |
42744 KB |
Output is correct |
27 |
Correct |
232 ms |
52100 KB |
Output is correct |
28 |
Correct |
307 ms |
97096 KB |
Output is correct |
29 |
Correct |
307 ms |
95224 KB |
Output is correct |
30 |
Correct |
247 ms |
52088 KB |
Output is correct |
31 |
Correct |
233 ms |
52088 KB |
Output is correct |
32 |
Correct |
289 ms |
52088 KB |
Output is correct |
33 |
Correct |
261 ms |
57208 KB |
Output is correct |
34 |
Correct |
348 ms |
88952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
512 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
4 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
6 ms |
640 KB |
Output is correct |
22 |
Correct |
6 ms |
768 KB |
Output is correct |
23 |
Correct |
6 ms |
768 KB |
Output is correct |
24 |
Correct |
6 ms |
768 KB |
Output is correct |
25 |
Correct |
6 ms |
768 KB |
Output is correct |
26 |
Correct |
6 ms |
896 KB |
Output is correct |
27 |
Correct |
5 ms |
640 KB |
Output is correct |
28 |
Correct |
6 ms |
768 KB |
Output is correct |
29 |
Correct |
6 ms |
768 KB |
Output is correct |
30 |
Correct |
6 ms |
768 KB |
Output is correct |
31 |
Correct |
6 ms |
768 KB |
Output is correct |
32 |
Correct |
6 ms |
768 KB |
Output is correct |
33 |
Correct |
6 ms |
768 KB |
Output is correct |
34 |
Correct |
6 ms |
640 KB |
Output is correct |
35 |
Correct |
5 ms |
640 KB |
Output is correct |
36 |
Correct |
5 ms |
640 KB |
Output is correct |
37 |
Correct |
6 ms |
640 KB |
Output is correct |
38 |
Correct |
6 ms |
640 KB |
Output is correct |
39 |
Correct |
135 ms |
32248 KB |
Output is correct |
40 |
Correct |
133 ms |
32248 KB |
Output is correct |
41 |
Correct |
129 ms |
31864 KB |
Output is correct |
42 |
Correct |
139 ms |
31480 KB |
Output is correct |
43 |
Correct |
161 ms |
44408 KB |
Output is correct |
44 |
Correct |
131 ms |
34424 KB |
Output is correct |
45 |
Correct |
112 ms |
33784 KB |
Output is correct |
46 |
Correct |
82 ms |
42744 KB |
Output is correct |
47 |
Correct |
232 ms |
52100 KB |
Output is correct |
48 |
Correct |
307 ms |
97096 KB |
Output is correct |
49 |
Correct |
307 ms |
95224 KB |
Output is correct |
50 |
Correct |
247 ms |
52088 KB |
Output is correct |
51 |
Correct |
233 ms |
52088 KB |
Output is correct |
52 |
Correct |
289 ms |
52088 KB |
Output is correct |
53 |
Correct |
261 ms |
57208 KB |
Output is correct |
54 |
Correct |
348 ms |
88952 KB |
Output is correct |
55 |
Correct |
20 ms |
4480 KB |
Output is correct |
56 |
Correct |
13 ms |
3328 KB |
Output is correct |
57 |
Correct |
83 ms |
29816 KB |
Output is correct |
58 |
Correct |
71 ms |
22120 KB |
Output is correct |
59 |
Correct |
108 ms |
49016 KB |
Output is correct |
60 |
Correct |
305 ms |
95992 KB |
Output is correct |
61 |
Correct |
273 ms |
55632 KB |
Output is correct |
62 |
Correct |
243 ms |
51960 KB |
Output is correct |
63 |
Correct |
286 ms |
52344 KB |
Output is correct |
64 |
Correct |
488 ms |
106372 KB |
Output is correct |
65 |
Correct |
487 ms |
104056 KB |
Output is correct |
66 |
Correct |
314 ms |
90232 KB |
Output is correct |
67 |
Correct |
208 ms |
44384 KB |
Output is correct |
68 |
Correct |
359 ms |
67344 KB |
Output is correct |
69 |
Correct |
376 ms |
72336 KB |
Output is correct |
70 |
Correct |
351 ms |
64632 KB |
Output is correct |