답안 #426979

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
426979 2021-06-14T11:32:44 Z LittlePants 경주 (Race) (IOI11_race) C++17
100 / 100
654 ms 105656 KB
#include "race.h"
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
#pragma loop-opt(on)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2,fma,tune=native")
#define pb push_back
#define eb emplace_back
#define push emplace
#define lb(x, v) lower_bound(all(x), v)
#define ub(x, v) upper_bound(all(x), v)
#define sz(x) (int)(x.size())
#define re(x) reverse(all(x))
#define uni(x) x.resize(unique(all(x)) - x.begin())
#define all(x) x.begin(), x.end()
#define mem(x, v) memset(x, v, sizeof x); 
#define pii pair<int, int>
#define inf 1e9
#define INF 1e18
#define mod 1000000007
#define F first
#define S second
#define IO ios_base::sync_with_stdio(0); cin.tie(0);
#define chmax(a, b) (a = (b > a ? b : a))
#define chmin(a, b) (a = (b < a ? b : a))
#define ll long long
using namespace std;

void trace_() {cerr << "\n";}
template<typename T1, typename... T2> void trace_(T1 t1, T2... t2) {cerr << ' ' << t1; trace_(t2...); }
#define trace(...) cerr << "[" << #__VA_ARGS__ << "] :", trace_(__VA_ARGS__);

const int mxN = 2e5 + 5;
int n, k, ans = inf, sz[mxN], bson[mxN], bw[mxN];
ll dep[mxN];
vector<pii> g[mxN];

void pre(int u, int p) {
	sz[u] = 1;
	int id = -1;
	for (auto [v, w] : g[u]) {
		if (v == p) continue;
		dep[v] = dep[u] + w;
		pre(v, u);
		sz[u] += sz[v];
		if (id == -1 or sz[id] < sz[v]) id = v;
	}
	bson[u] = id;
}

map<ll, int> dfs(int u, int p) {
	map<ll, int> mp, t;
	int d = 0;
	if (~bson[u]) { 
		mp = dfs(bson[u], u);
		d = -mp[dep[bson[u]]] + 1;
	}
	mp[dep[u]] = -d;
	if (mp.count(dep[u] + k)) {
		chmin(ans, mp[dep[u] + k] + d);
	}

	for (auto [v, w] : g[u]) {
		if (v == bson[u] or v == p) continue;	
		t = dfs(v, u);
		int td = -t[dep[v]] + 1;
		for (auto [depth, step] : t) {	
			if (depth - dep[u] <= k and mp.count(k + 2 * dep[u] - depth)) {
				chmin(ans, step + mp[k + 2 * dep[u] - depth] + d + td);
			}
		}
		for (auto [depth, step] : t) {
			if (mp.count(depth)) {
				chmin(mp[depth], step + td - d);
			} else {
				mp[depth] = step + td - d;
			}
		}
	}
	
	return mp;
}

int best_path(int N, int K, int H[][2], int L[]) {
	n = N; k = K;
	dep[0] = 0;
	for (int i = 0; i < n - 1; i++) {
		g[H[i][0]].pb({H[i][1], L[i]});
		g[H[i][1]].pb({H[i][0], L[i]});
	}
	mem(bson, -1);

	pre(0, -1);
	dfs(0, -1);

	if (ans == inf) ans = -1;
	return ans;
}

Compilation message

race.cpp:4: warning: ignoring '#pragma loop ' [-Wunknown-pragmas]
    4 | #pragma loop-opt(on)
      |
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 5836 KB Output is correct
2 Correct 4 ms 5768 KB Output is correct
3 Correct 4 ms 5836 KB Output is correct
4 Correct 4 ms 5776 KB Output is correct
5 Correct 4 ms 5836 KB Output is correct
6 Correct 4 ms 5780 KB Output is correct
7 Correct 4 ms 5836 KB Output is correct
8 Correct 4 ms 5836 KB Output is correct
9 Correct 4 ms 5836 KB Output is correct
10 Correct 4 ms 5784 KB Output is correct
11 Correct 4 ms 5764 KB Output is correct
12 Correct 4 ms 5836 KB Output is correct
13 Correct 4 ms 5836 KB Output is correct
14 Correct 5 ms 5836 KB Output is correct
15 Correct 4 ms 5776 KB Output is correct
16 Correct 5 ms 5836 KB Output is correct
17 Correct 4 ms 5836 KB Output is correct
18 Correct 4 ms 5776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 5836 KB Output is correct
2 Correct 4 ms 5768 KB Output is correct
3 Correct 4 ms 5836 KB Output is correct
4 Correct 4 ms 5776 KB Output is correct
5 Correct 4 ms 5836 KB Output is correct
6 Correct 4 ms 5780 KB Output is correct
7 Correct 4 ms 5836 KB Output is correct
8 Correct 4 ms 5836 KB Output is correct
9 Correct 4 ms 5836 KB Output is correct
10 Correct 4 ms 5784 KB Output is correct
11 Correct 4 ms 5764 KB Output is correct
12 Correct 4 ms 5836 KB Output is correct
13 Correct 4 ms 5836 KB Output is correct
14 Correct 5 ms 5836 KB Output is correct
15 Correct 4 ms 5776 KB Output is correct
16 Correct 5 ms 5836 KB Output is correct
17 Correct 4 ms 5836 KB Output is correct
18 Correct 4 ms 5776 KB Output is correct
19 Correct 4 ms 5708 KB Output is correct
20 Correct 4 ms 5708 KB Output is correct
21 Correct 5 ms 5836 KB Output is correct
22 Correct 5 ms 5836 KB Output is correct
23 Correct 5 ms 5836 KB Output is correct
24 Correct 5 ms 5932 KB Output is correct
25 Correct 6 ms 5836 KB Output is correct
26 Correct 5 ms 5836 KB Output is correct
27 Correct 5 ms 5836 KB Output is correct
28 Correct 5 ms 5836 KB Output is correct
29 Correct 6 ms 5836 KB Output is correct
30 Correct 5 ms 5836 KB Output is correct
31 Correct 5 ms 5836 KB Output is correct
32 Correct 5 ms 5964 KB Output is correct
33 Correct 5 ms 5964 KB Output is correct
34 Correct 6 ms 5924 KB Output is correct
35 Correct 5 ms 5964 KB Output is correct
36 Correct 5 ms 5964 KB Output is correct
37 Correct 5 ms 5964 KB Output is correct
38 Correct 5 ms 5964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 5836 KB Output is correct
2 Correct 4 ms 5768 KB Output is correct
3 Correct 4 ms 5836 KB Output is correct
4 Correct 4 ms 5776 KB Output is correct
5 Correct 4 ms 5836 KB Output is correct
6 Correct 4 ms 5780 KB Output is correct
7 Correct 4 ms 5836 KB Output is correct
8 Correct 4 ms 5836 KB Output is correct
9 Correct 4 ms 5836 KB Output is correct
10 Correct 4 ms 5784 KB Output is correct
11 Correct 4 ms 5764 KB Output is correct
12 Correct 4 ms 5836 KB Output is correct
13 Correct 4 ms 5836 KB Output is correct
14 Correct 5 ms 5836 KB Output is correct
15 Correct 4 ms 5776 KB Output is correct
16 Correct 5 ms 5836 KB Output is correct
17 Correct 4 ms 5836 KB Output is correct
18 Correct 4 ms 5776 KB Output is correct
19 Correct 132 ms 13216 KB Output is correct
20 Correct 135 ms 13272 KB Output is correct
21 Correct 133 ms 13236 KB Output is correct
22 Correct 171 ms 13224 KB Output is correct
23 Correct 149 ms 13716 KB Output is correct
24 Correct 129 ms 13488 KB Output is correct
25 Correct 141 ms 33080 KB Output is correct
26 Correct 74 ms 50092 KB Output is correct
27 Correct 218 ms 19864 KB Output is correct
28 Correct 377 ms 105656 KB Output is correct
29 Correct 374 ms 101060 KB Output is correct
30 Correct 248 ms 20036 KB Output is correct
31 Correct 261 ms 20052 KB Output is correct
32 Correct 283 ms 20216 KB Output is correct
33 Correct 264 ms 19668 KB Output is correct
34 Correct 410 ms 32388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 5836 KB Output is correct
2 Correct 4 ms 5768 KB Output is correct
3 Correct 4 ms 5836 KB Output is correct
4 Correct 4 ms 5776 KB Output is correct
5 Correct 4 ms 5836 KB Output is correct
6 Correct 4 ms 5780 KB Output is correct
7 Correct 4 ms 5836 KB Output is correct
8 Correct 4 ms 5836 KB Output is correct
9 Correct 4 ms 5836 KB Output is correct
10 Correct 4 ms 5784 KB Output is correct
11 Correct 4 ms 5764 KB Output is correct
12 Correct 4 ms 5836 KB Output is correct
13 Correct 4 ms 5836 KB Output is correct
14 Correct 5 ms 5836 KB Output is correct
15 Correct 4 ms 5776 KB Output is correct
16 Correct 5 ms 5836 KB Output is correct
17 Correct 4 ms 5836 KB Output is correct
18 Correct 4 ms 5776 KB Output is correct
19 Correct 4 ms 5708 KB Output is correct
20 Correct 4 ms 5708 KB Output is correct
21 Correct 5 ms 5836 KB Output is correct
22 Correct 5 ms 5836 KB Output is correct
23 Correct 5 ms 5836 KB Output is correct
24 Correct 5 ms 5932 KB Output is correct
25 Correct 6 ms 5836 KB Output is correct
26 Correct 5 ms 5836 KB Output is correct
27 Correct 5 ms 5836 KB Output is correct
28 Correct 5 ms 5836 KB Output is correct
29 Correct 6 ms 5836 KB Output is correct
30 Correct 5 ms 5836 KB Output is correct
31 Correct 5 ms 5836 KB Output is correct
32 Correct 5 ms 5964 KB Output is correct
33 Correct 5 ms 5964 KB Output is correct
34 Correct 6 ms 5924 KB Output is correct
35 Correct 5 ms 5964 KB Output is correct
36 Correct 5 ms 5964 KB Output is correct
37 Correct 5 ms 5964 KB Output is correct
38 Correct 5 ms 5964 KB Output is correct
39 Correct 132 ms 13216 KB Output is correct
40 Correct 135 ms 13272 KB Output is correct
41 Correct 133 ms 13236 KB Output is correct
42 Correct 171 ms 13224 KB Output is correct
43 Correct 149 ms 13716 KB Output is correct
44 Correct 129 ms 13488 KB Output is correct
45 Correct 141 ms 33080 KB Output is correct
46 Correct 74 ms 50092 KB Output is correct
47 Correct 218 ms 19864 KB Output is correct
48 Correct 377 ms 105656 KB Output is correct
49 Correct 374 ms 101060 KB Output is correct
50 Correct 248 ms 20036 KB Output is correct
51 Correct 261 ms 20052 KB Output is correct
52 Correct 283 ms 20216 KB Output is correct
53 Correct 264 ms 19668 KB Output is correct
54 Correct 410 ms 32388 KB Output is correct
55 Correct 19 ms 6988 KB Output is correct
56 Correct 12 ms 6456 KB Output is correct
57 Correct 71 ms 13324 KB Output is correct
58 Correct 58 ms 13108 KB Output is correct
59 Correct 117 ms 56432 KB Output is correct
60 Correct 383 ms 104320 KB Output is correct
61 Correct 264 ms 23364 KB Output is correct
62 Correct 239 ms 21592 KB Output is correct
63 Correct 284 ms 21572 KB Output is correct
64 Correct 654 ms 28196 KB Output is correct
65 Correct 553 ms 34568 KB Output is correct
66 Correct 391 ms 92392 KB Output is correct
67 Correct 244 ms 21680 KB Output is correct
68 Correct 548 ms 32512 KB Output is correct
69 Correct 472 ms 32832 KB Output is correct
70 Correct 445 ms 31576 KB Output is correct