Submission #674887

# Submission time Handle Problem Language Result Execution time Memory
674887 2022-12-26T12:49:32 Z penguin133 Race (IOI11_race) C++14
100 / 100
433 ms 114120 KB
#include "race.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define pi pair<ll, ll>
#define pii pair<ll, pi>
#define fi first
#define se second

set<pi>s[200005];
ll os[200005], os2[200005];
vector<pi>v[200005];
ll n, k;
ll ans = 1e18;
void dfs(int x, int par){
	s[x].insert({0, 0});
	for(auto [i, j] : v[x]){
		if(i == par)continue;
		dfs(i, x);
		os[i] += j;
		os2[i]++;
		if(s[i].size() > s[x].size())swap(s[i], s[x]), swap(os[i], os[x]), swap(os2[i], os2[x]);
		for(auto [el, el2] : s[i]){
			int real = el + os[i];
			int needed = k - real - os[x];
			auto it = s[x].lower_bound({needed, -1e9});
			if(it == s[x].end())continue;
			pi tmp = *it;
			if(tmp.fi == needed)ans = min(ans, os2[x] + os2[i] + el2 + tmp.se);
		}
		for(auto [el, el2] : s[i]){
			int real = el + os[i], real2 = el2 + os2[i];
			real -= os[x], real2 -= os2[x];
			s[x].insert({real, real2});
		}
	}
	//cout << x << '\n';
	//for(auto [i, j] : s[x])cout << i << " " << j << '\n';
	//cout << os[x] << " " << os2[x] << '\n';
}

int best_path(int N, int K, int H[][2], int L[])
{
	n = N, k = K;
	for(int i=0;i<N-1;i++){
		v[H[i][0]].push_back({H[i][1], L[i]});
		v[H[i][1]].push_back({H[i][0], L[i]});
	}
	dfs(0, -1);
  if(ans == 1e18)return -1;
  else return (int32_t)ans;
}

Compilation message

race.cpp: In function 'void dfs(int, int)':
race.cpp:18:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   18 |  for(auto [i, j] : v[x]){
      |           ^
race.cpp:24:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   24 |   for(auto [el, el2] : s[i]){
      |            ^
race.cpp:32:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   32 |   for(auto [el, el2] : s[i]){
      |            ^
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14420 KB Output is correct
2 Correct 7 ms 14412 KB Output is correct
3 Correct 8 ms 14420 KB Output is correct
4 Correct 7 ms 14412 KB Output is correct
5 Correct 8 ms 14420 KB Output is correct
6 Correct 7 ms 14420 KB Output is correct
7 Correct 7 ms 14420 KB Output is correct
8 Correct 7 ms 14412 KB Output is correct
9 Correct 8 ms 14420 KB Output is correct
10 Correct 7 ms 14420 KB Output is correct
11 Correct 7 ms 14420 KB Output is correct
12 Correct 7 ms 14420 KB Output is correct
13 Correct 8 ms 14420 KB Output is correct
14 Correct 8 ms 14460 KB Output is correct
15 Correct 8 ms 14420 KB Output is correct
16 Correct 8 ms 14340 KB Output is correct
17 Correct 7 ms 14420 KB Output is correct
18 Correct 10 ms 14408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14420 KB Output is correct
2 Correct 7 ms 14412 KB Output is correct
3 Correct 8 ms 14420 KB Output is correct
4 Correct 7 ms 14412 KB Output is correct
5 Correct 8 ms 14420 KB Output is correct
6 Correct 7 ms 14420 KB Output is correct
7 Correct 7 ms 14420 KB Output is correct
8 Correct 7 ms 14412 KB Output is correct
9 Correct 8 ms 14420 KB Output is correct
10 Correct 7 ms 14420 KB Output is correct
11 Correct 7 ms 14420 KB Output is correct
12 Correct 7 ms 14420 KB Output is correct
13 Correct 8 ms 14420 KB Output is correct
14 Correct 8 ms 14460 KB Output is correct
15 Correct 8 ms 14420 KB Output is correct
16 Correct 8 ms 14340 KB Output is correct
17 Correct 7 ms 14420 KB Output is correct
18 Correct 10 ms 14408 KB Output is correct
19 Correct 8 ms 14420 KB Output is correct
20 Correct 7 ms 14412 KB Output is correct
21 Correct 8 ms 14676 KB Output is correct
22 Correct 9 ms 14804 KB Output is correct
23 Correct 8 ms 14676 KB Output is correct
24 Correct 10 ms 14676 KB Output is correct
25 Correct 8 ms 14644 KB Output is correct
26 Correct 9 ms 14676 KB Output is correct
27 Correct 8 ms 14548 KB Output is correct
28 Correct 8 ms 14676 KB Output is correct
29 Correct 8 ms 14676 KB Output is correct
30 Correct 9 ms 14676 KB Output is correct
31 Correct 9 ms 14676 KB Output is correct
32 Correct 9 ms 14680 KB Output is correct
33 Correct 8 ms 14684 KB Output is correct
34 Correct 8 ms 14676 KB Output is correct
35 Correct 8 ms 14704 KB Output is correct
36 Correct 8 ms 14676 KB Output is correct
37 Correct 9 ms 14672 KB Output is correct
38 Correct 8 ms 14672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14420 KB Output is correct
2 Correct 7 ms 14412 KB Output is correct
3 Correct 8 ms 14420 KB Output is correct
4 Correct 7 ms 14412 KB Output is correct
5 Correct 8 ms 14420 KB Output is correct
6 Correct 7 ms 14420 KB Output is correct
7 Correct 7 ms 14420 KB Output is correct
8 Correct 7 ms 14412 KB Output is correct
9 Correct 8 ms 14420 KB Output is correct
10 Correct 7 ms 14420 KB Output is correct
11 Correct 7 ms 14420 KB Output is correct
12 Correct 7 ms 14420 KB Output is correct
13 Correct 8 ms 14420 KB Output is correct
14 Correct 8 ms 14460 KB Output is correct
15 Correct 8 ms 14420 KB Output is correct
16 Correct 8 ms 14340 KB Output is correct
17 Correct 7 ms 14420 KB Output is correct
18 Correct 10 ms 14408 KB Output is correct
19 Correct 135 ms 44112 KB Output is correct
20 Correct 139 ms 44020 KB Output is correct
21 Correct 133 ms 43328 KB Output is correct
22 Correct 146 ms 41892 KB Output is correct
23 Correct 179 ms 56488 KB Output is correct
24 Correct 123 ms 42444 KB Output is correct
25 Correct 131 ms 49244 KB Output is correct
26 Correct 83 ms 55972 KB Output is correct
27 Correct 204 ms 55828 KB Output is correct
28 Correct 294 ms 97924 KB Output is correct
29 Correct 297 ms 95936 KB Output is correct
30 Correct 187 ms 55784 KB Output is correct
31 Correct 210 ms 55680 KB Output is correct
32 Correct 285 ms 55820 KB Output is correct
33 Correct 231 ms 57488 KB Output is correct
34 Correct 333 ms 90472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14420 KB Output is correct
2 Correct 7 ms 14412 KB Output is correct
3 Correct 8 ms 14420 KB Output is correct
4 Correct 7 ms 14412 KB Output is correct
5 Correct 8 ms 14420 KB Output is correct
6 Correct 7 ms 14420 KB Output is correct
7 Correct 7 ms 14420 KB Output is correct
8 Correct 7 ms 14412 KB Output is correct
9 Correct 8 ms 14420 KB Output is correct
10 Correct 7 ms 14420 KB Output is correct
11 Correct 7 ms 14420 KB Output is correct
12 Correct 7 ms 14420 KB Output is correct
13 Correct 8 ms 14420 KB Output is correct
14 Correct 8 ms 14460 KB Output is correct
15 Correct 8 ms 14420 KB Output is correct
16 Correct 8 ms 14340 KB Output is correct
17 Correct 7 ms 14420 KB Output is correct
18 Correct 10 ms 14408 KB Output is correct
19 Correct 8 ms 14420 KB Output is correct
20 Correct 7 ms 14412 KB Output is correct
21 Correct 8 ms 14676 KB Output is correct
22 Correct 9 ms 14804 KB Output is correct
23 Correct 8 ms 14676 KB Output is correct
24 Correct 10 ms 14676 KB Output is correct
25 Correct 8 ms 14644 KB Output is correct
26 Correct 9 ms 14676 KB Output is correct
27 Correct 8 ms 14548 KB Output is correct
28 Correct 8 ms 14676 KB Output is correct
29 Correct 8 ms 14676 KB Output is correct
30 Correct 9 ms 14676 KB Output is correct
31 Correct 9 ms 14676 KB Output is correct
32 Correct 9 ms 14680 KB Output is correct
33 Correct 8 ms 14684 KB Output is correct
34 Correct 8 ms 14676 KB Output is correct
35 Correct 8 ms 14704 KB Output is correct
36 Correct 8 ms 14676 KB Output is correct
37 Correct 9 ms 14672 KB Output is correct
38 Correct 8 ms 14672 KB Output is correct
39 Correct 135 ms 44112 KB Output is correct
40 Correct 139 ms 44020 KB Output is correct
41 Correct 133 ms 43328 KB Output is correct
42 Correct 146 ms 41892 KB Output is correct
43 Correct 179 ms 56488 KB Output is correct
44 Correct 123 ms 42444 KB Output is correct
45 Correct 131 ms 49244 KB Output is correct
46 Correct 83 ms 55972 KB Output is correct
47 Correct 204 ms 55828 KB Output is correct
48 Correct 294 ms 97924 KB Output is correct
49 Correct 297 ms 95936 KB Output is correct
50 Correct 187 ms 55784 KB Output is correct
51 Correct 210 ms 55680 KB Output is correct
52 Correct 285 ms 55820 KB Output is correct
53 Correct 231 ms 57488 KB Output is correct
54 Correct 333 ms 90472 KB Output is correct
55 Correct 25 ms 17980 KB Output is correct
56 Correct 16 ms 16852 KB Output is correct
57 Correct 90 ms 38740 KB Output is correct
58 Correct 50 ms 29096 KB Output is correct
59 Correct 81 ms 55948 KB Output is correct
60 Correct 258 ms 96420 KB Output is correct
61 Correct 234 ms 61524 KB Output is correct
62 Correct 205 ms 55812 KB Output is correct
63 Correct 278 ms 55888 KB Output is correct
64 Correct 433 ms 114120 KB Output is correct
65 Correct 422 ms 105768 KB Output is correct
66 Correct 299 ms 91340 KB Output is correct
67 Correct 197 ms 45524 KB Output is correct
68 Correct 343 ms 70800 KB Output is correct
69 Correct 337 ms 76028 KB Output is correct
70 Correct 315 ms 68172 KB Output is correct