답안 #474474

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
474474 2021-09-18T11:59:03 Z disastah 경주 (Race) (IOI11_race) C++17
100 / 100
526 ms 103892 KB
#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
#define ar array
using namespace std;
typedef long double ld;
typedef long long ll;
const int inf=1e9+1e8;
const ll linf=4e18+18;
const int N=2e5;
int n, k, h[N], ans=inf; ll dep[N];
map<ll,int> dp[N];
vector<ar<int,2>> g[N];
int get(int v, ll x) {
	return (dp[v].find(x)!=dp[v].end()?dp[v][x]:inf);
}
void dfs(int v, int p=-1) {
	dp[v][dep[v]]=h[v];
	for (auto &[u,c] : g[v]) {
		if (u!=p) {
			h[u]=h[v]+1, dep[u]=dep[v]+c;
			dfs(u,v);
			if (dp[u].size()>dp[v].size()) swap(dp[v],dp[u]);
			for (auto &[x,dh] : dp[u]) {
				ans=min(ans,dh+get(v,k-x+2*dep[v])-2*h[v]);
			}
			for (auto &[x,dh] : dp[u]) {
				if (dp[v].find(x)==dp[v].end()) dp[v][x]=dh;
				else dp[v][x]=min(dp[v][x],dh);
			}
		}
	}
}
int best_path(int n0, int k0, int h[][2], int l[]) {
	n=n0, k=k0;
	for (int i=0; i<n-1; ++i) {
		g[h[i][0]].push_back({h[i][1],l[i]});
		g[h[i][1]].push_back({h[i][0],l[i]});
	}
	dfs(0);
	return (ans<n?ans:-1);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14412 KB Output is correct
2 Correct 9 ms 14384 KB Output is correct
3 Correct 9 ms 14400 KB Output is correct
4 Correct 9 ms 14412 KB Output is correct
5 Correct 9 ms 14396 KB Output is correct
6 Correct 9 ms 14412 KB Output is correct
7 Correct 9 ms 14412 KB Output is correct
8 Correct 10 ms 14396 KB Output is correct
9 Correct 9 ms 14352 KB Output is correct
10 Correct 9 ms 14412 KB Output is correct
11 Correct 9 ms 14412 KB Output is correct
12 Correct 9 ms 14412 KB Output is correct
13 Correct 9 ms 14412 KB Output is correct
14 Correct 10 ms 14400 KB Output is correct
15 Correct 9 ms 14412 KB Output is correct
16 Correct 10 ms 14412 KB Output is correct
17 Correct 9 ms 14412 KB Output is correct
18 Correct 9 ms 14412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14412 KB Output is correct
2 Correct 9 ms 14384 KB Output is correct
3 Correct 9 ms 14400 KB Output is correct
4 Correct 9 ms 14412 KB Output is correct
5 Correct 9 ms 14396 KB Output is correct
6 Correct 9 ms 14412 KB Output is correct
7 Correct 9 ms 14412 KB Output is correct
8 Correct 10 ms 14396 KB Output is correct
9 Correct 9 ms 14352 KB Output is correct
10 Correct 9 ms 14412 KB Output is correct
11 Correct 9 ms 14412 KB Output is correct
12 Correct 9 ms 14412 KB Output is correct
13 Correct 9 ms 14412 KB Output is correct
14 Correct 10 ms 14400 KB Output is correct
15 Correct 9 ms 14412 KB Output is correct
16 Correct 10 ms 14412 KB Output is correct
17 Correct 9 ms 14412 KB Output is correct
18 Correct 9 ms 14412 KB Output is correct
19 Correct 9 ms 14440 KB Output is correct
20 Correct 9 ms 14412 KB Output is correct
21 Correct 10 ms 14668 KB Output is correct
22 Correct 10 ms 14668 KB Output is correct
23 Correct 10 ms 14668 KB Output is correct
24 Correct 10 ms 14668 KB Output is correct
25 Correct 12 ms 14668 KB Output is correct
26 Correct 10 ms 14668 KB Output is correct
27 Correct 10 ms 14540 KB Output is correct
28 Correct 13 ms 14668 KB Output is correct
29 Correct 10 ms 14684 KB Output is correct
30 Correct 10 ms 14668 KB Output is correct
31 Correct 11 ms 14636 KB Output is correct
32 Correct 10 ms 14668 KB Output is correct
33 Correct 10 ms 14668 KB Output is correct
34 Correct 10 ms 14668 KB Output is correct
35 Correct 10 ms 14668 KB Output is correct
36 Correct 10 ms 14540 KB Output is correct
37 Correct 9 ms 14540 KB Output is correct
38 Correct 10 ms 14668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14412 KB Output is correct
2 Correct 9 ms 14384 KB Output is correct
3 Correct 9 ms 14400 KB Output is correct
4 Correct 9 ms 14412 KB Output is correct
5 Correct 9 ms 14396 KB Output is correct
6 Correct 9 ms 14412 KB Output is correct
7 Correct 9 ms 14412 KB Output is correct
8 Correct 10 ms 14396 KB Output is correct
9 Correct 9 ms 14352 KB Output is correct
10 Correct 9 ms 14412 KB Output is correct
11 Correct 9 ms 14412 KB Output is correct
12 Correct 9 ms 14412 KB Output is correct
13 Correct 9 ms 14412 KB Output is correct
14 Correct 10 ms 14400 KB Output is correct
15 Correct 9 ms 14412 KB Output is correct
16 Correct 10 ms 14412 KB Output is correct
17 Correct 9 ms 14412 KB Output is correct
18 Correct 9 ms 14412 KB Output is correct
19 Correct 148 ms 37276 KB Output is correct
20 Correct 177 ms 37356 KB Output is correct
21 Correct 171 ms 37020 KB Output is correct
22 Correct 148 ms 36636 KB Output is correct
23 Correct 190 ms 49384 KB Output is correct
24 Correct 161 ms 40132 KB Output is correct
25 Correct 146 ms 36288 KB Output is correct
26 Correct 78 ms 43080 KB Output is correct
27 Correct 240 ms 48564 KB Output is correct
28 Correct 413 ms 84672 KB Output is correct
29 Correct 366 ms 83360 KB Output is correct
30 Correct 231 ms 48600 KB Output is correct
31 Correct 251 ms 48572 KB Output is correct
32 Correct 290 ms 48784 KB Output is correct
33 Correct 290 ms 53436 KB Output is correct
34 Correct 453 ms 86448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14412 KB Output is correct
2 Correct 9 ms 14384 KB Output is correct
3 Correct 9 ms 14400 KB Output is correct
4 Correct 9 ms 14412 KB Output is correct
5 Correct 9 ms 14396 KB Output is correct
6 Correct 9 ms 14412 KB Output is correct
7 Correct 9 ms 14412 KB Output is correct
8 Correct 10 ms 14396 KB Output is correct
9 Correct 9 ms 14352 KB Output is correct
10 Correct 9 ms 14412 KB Output is correct
11 Correct 9 ms 14412 KB Output is correct
12 Correct 9 ms 14412 KB Output is correct
13 Correct 9 ms 14412 KB Output is correct
14 Correct 10 ms 14400 KB Output is correct
15 Correct 9 ms 14412 KB Output is correct
16 Correct 10 ms 14412 KB Output is correct
17 Correct 9 ms 14412 KB Output is correct
18 Correct 9 ms 14412 KB Output is correct
19 Correct 9 ms 14440 KB Output is correct
20 Correct 9 ms 14412 KB Output is correct
21 Correct 10 ms 14668 KB Output is correct
22 Correct 10 ms 14668 KB Output is correct
23 Correct 10 ms 14668 KB Output is correct
24 Correct 10 ms 14668 KB Output is correct
25 Correct 12 ms 14668 KB Output is correct
26 Correct 10 ms 14668 KB Output is correct
27 Correct 10 ms 14540 KB Output is correct
28 Correct 13 ms 14668 KB Output is correct
29 Correct 10 ms 14684 KB Output is correct
30 Correct 10 ms 14668 KB Output is correct
31 Correct 11 ms 14636 KB Output is correct
32 Correct 10 ms 14668 KB Output is correct
33 Correct 10 ms 14668 KB Output is correct
34 Correct 10 ms 14668 KB Output is correct
35 Correct 10 ms 14668 KB Output is correct
36 Correct 10 ms 14540 KB Output is correct
37 Correct 9 ms 14540 KB Output is correct
38 Correct 10 ms 14668 KB Output is correct
39 Correct 148 ms 37276 KB Output is correct
40 Correct 177 ms 37356 KB Output is correct
41 Correct 171 ms 37020 KB Output is correct
42 Correct 148 ms 36636 KB Output is correct
43 Correct 190 ms 49384 KB Output is correct
44 Correct 161 ms 40132 KB Output is correct
45 Correct 146 ms 36288 KB Output is correct
46 Correct 78 ms 43080 KB Output is correct
47 Correct 240 ms 48564 KB Output is correct
48 Correct 413 ms 84672 KB Output is correct
49 Correct 366 ms 83360 KB Output is correct
50 Correct 231 ms 48600 KB Output is correct
51 Correct 251 ms 48572 KB Output is correct
52 Correct 290 ms 48784 KB Output is correct
53 Correct 290 ms 53436 KB Output is correct
54 Correct 453 ms 86448 KB Output is correct
55 Correct 30 ms 17616 KB Output is correct
56 Correct 20 ms 16384 KB Output is correct
57 Correct 98 ms 34824 KB Output is correct
58 Correct 62 ms 27900 KB Output is correct
59 Correct 110 ms 49288 KB Output is correct
60 Correct 372 ms 83540 KB Output is correct
61 Correct 260 ms 52164 KB Output is correct
62 Correct 225 ms 48668 KB Output is correct
63 Correct 282 ms 48860 KB Output is correct
64 Correct 526 ms 103892 KB Output is correct
65 Correct 514 ms 102004 KB Output is correct
66 Correct 367 ms 80324 KB Output is correct
67 Correct 225 ms 43048 KB Output is correct
68 Correct 406 ms 65560 KB Output is correct
69 Correct 505 ms 70756 KB Output is correct
70 Correct 377 ms 63536 KB Output is correct