# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
314003 |
2020-10-17T19:05:14 Z |
tatyam |
Race (IOI11_race) |
C++17 |
|
669 ms |
262148 KB |
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
const ll INF = 0x1fffffffffffffff;
bool chmin(ll& a, ll b){ if(a > b){ a = b; return 1; } return 0; }
bool chmax(ll& a, ll b){ if(a < b){ a = b; return 1; } return 0; }
ll k;
ll solve(vector<vector<pair<ll, ll>>> g){
if(g.size() == 1) return INF;
const ll n = g.size();
vector<ll> siz(n, 1);
ll max = 0, a, b, d;
auto dfs_size = [&](ll from, ll at, ll dist, auto dfs) -> void {
for(auto [i, d] : g[at]) if(i != from){
dfs(at, i, d, dfs);
siz[at] += siz[i];
}
if(siz[at] * 2 <= n && chmax(max, siz[at])){
a = from; b = at; d = dist;
}
};
dfs_size(-1, 0, 0, dfs_size);
unordered_map<ll, ll> lower;
vector<vector<pair<ll, ll>>> g_lower(1), g_upper(1);
auto dfs_lower = [&](ll from, ll at, ll depth, ll dist, auto dfs) -> void {
if(!lower.try_emplace(dist, depth).second) chmax(lower[dist], depth);
const ll at2 = g_lower.size() - 1;
for(auto [i, d] : g[at]) if(i != from){
g_lower[at2].emplace_back(g_lower.size(), d);
g_lower.push_back({{at2, d}});
dfs(at, i, depth - 1, dist - d, dfs);
}
};
dfs_lower(a, b, -1, -d, dfs_lower);
ll ans = INF;
auto dfs_upper = [&](ll from, ll at, ll depth, ll dist, auto dfs) -> void {
if(lower.count(dist - k)) chmin(ans, depth - lower[dist - k]);
const ll at2 = g_upper.size() - 1;
for(auto [i, d] : g[at]) if(i != from){
g_upper[at2].emplace_back(g_upper.size(), d);
g_upper.push_back({{at2, d}});
dfs(at, i, depth + 1, dist + d, dfs);
}
};
dfs_upper(b, a, 0, 0, dfs_upper);
chmin(ans, solve(g_lower));
chmin(ans, solve(g_upper));
return ans;
}
int best_path(int N, int K, int H[][2], int L[]){
k = K;
vector<vector<pair<ll, ll>>> g(N);
for(ll i = 0; i < N - 1; i++){
const auto [a, b] = H[i];
const int c = L[i];
g[a].emplace_back(b, c);
g[b].emplace_back(a, c);
}
return solve(g);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
768 KB |
Output is correct |
22 |
Correct |
4 ms |
768 KB |
Output is correct |
23 |
Correct |
6 ms |
896 KB |
Output is correct |
24 |
Correct |
5 ms |
1024 KB |
Output is correct |
25 |
Correct |
5 ms |
896 KB |
Output is correct |
26 |
Correct |
5 ms |
896 KB |
Output is correct |
27 |
Correct |
4 ms |
896 KB |
Output is correct |
28 |
Correct |
5 ms |
896 KB |
Output is correct |
29 |
Correct |
5 ms |
896 KB |
Output is correct |
30 |
Correct |
5 ms |
896 KB |
Output is correct |
31 |
Correct |
5 ms |
1024 KB |
Output is correct |
32 |
Correct |
5 ms |
896 KB |
Output is correct |
33 |
Correct |
5 ms |
896 KB |
Output is correct |
34 |
Correct |
4 ms |
768 KB |
Output is correct |
35 |
Correct |
4 ms |
768 KB |
Output is correct |
36 |
Correct |
4 ms |
768 KB |
Output is correct |
37 |
Correct |
4 ms |
768 KB |
Output is correct |
38 |
Correct |
4 ms |
768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
623 ms |
44700 KB |
Output is correct |
20 |
Correct |
620 ms |
45188 KB |
Output is correct |
21 |
Correct |
617 ms |
46840 KB |
Output is correct |
22 |
Correct |
647 ms |
53812 KB |
Output is correct |
23 |
Correct |
601 ms |
47380 KB |
Output is correct |
24 |
Correct |
669 ms |
68376 KB |
Output is correct |
25 |
Correct |
551 ms |
49788 KB |
Output is correct |
26 |
Correct |
469 ms |
53940 KB |
Output is correct |
27 |
Runtime error |
637 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
768 KB |
Output is correct |
22 |
Correct |
4 ms |
768 KB |
Output is correct |
23 |
Correct |
6 ms |
896 KB |
Output is correct |
24 |
Correct |
5 ms |
1024 KB |
Output is correct |
25 |
Correct |
5 ms |
896 KB |
Output is correct |
26 |
Correct |
5 ms |
896 KB |
Output is correct |
27 |
Correct |
4 ms |
896 KB |
Output is correct |
28 |
Correct |
5 ms |
896 KB |
Output is correct |
29 |
Correct |
5 ms |
896 KB |
Output is correct |
30 |
Correct |
5 ms |
896 KB |
Output is correct |
31 |
Correct |
5 ms |
1024 KB |
Output is correct |
32 |
Correct |
5 ms |
896 KB |
Output is correct |
33 |
Correct |
5 ms |
896 KB |
Output is correct |
34 |
Correct |
4 ms |
768 KB |
Output is correct |
35 |
Correct |
4 ms |
768 KB |
Output is correct |
36 |
Correct |
4 ms |
768 KB |
Output is correct |
37 |
Correct |
4 ms |
768 KB |
Output is correct |
38 |
Correct |
4 ms |
768 KB |
Output is correct |
39 |
Correct |
623 ms |
44700 KB |
Output is correct |
40 |
Correct |
620 ms |
45188 KB |
Output is correct |
41 |
Correct |
617 ms |
46840 KB |
Output is correct |
42 |
Correct |
647 ms |
53812 KB |
Output is correct |
43 |
Correct |
601 ms |
47380 KB |
Output is correct |
44 |
Correct |
669 ms |
68376 KB |
Output is correct |
45 |
Correct |
551 ms |
49788 KB |
Output is correct |
46 |
Correct |
469 ms |
53940 KB |
Output is correct |
47 |
Runtime error |
637 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
48 |
Halted |
0 ms |
0 KB |
- |