Submission #828450

# Submission time Handle Problem Language Result Execution time Memory
828450 2023-08-17T09:41:36 Z AkramElOmrani Race (IOI11_race) C++17
100 / 100
294 ms 69736 KB
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,avx2,bmi,bmi2,popcnt,lzcnt")
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
 
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__);


const int INF = 1e9 + 5;
int ans = INF;
vector<vector<pair<int, int>>> adj;

// {distance, depth}
void dfs(int node, int p, map<int, int>& mp, int& k, int depth, int distance) {
	mp[distance] = depth;
	for(auto[x, w] : adj[node]) {
		if(p == x) continue;
		map<int, int> nxt;
		dfs(x, node, nxt, k, depth + 1, distance + w);
		if(mp.size() < nxt.size()) swap(mp, nxt);
		for(auto&[x, y] : nxt) {
			int new_dist = k + 2 * distance - x;
			if(mp.count(new_dist)) {
				ans = min(ans, mp[new_dist] + y - 2 * depth);
			}
		}
		for(auto&[x, y] : nxt) {
			if(mp.count(x)) {
				mp[x] = min(mp[x], y);
			} else {
				mp[x] = y;
			}
		}
	}
}

int best_path(int n, int k, int H[][2], int L[])
{
	adj.resize(n);
	for(int i = 0; i < n - 1; ++i) {
		adj[H[i][0]].emplace_back(H[i][1], L[i]);
		adj[H[i][1]].emplace_back(H[i][0], L[i]);
	}
	map<int, int> mp;
	dfs(0, -1, mp, k, 0, 0);
	if(ans == INF) {
		return -1;
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 428 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 468 KB Output is correct
35 Correct 1 ms 468 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 60 ms 7452 KB Output is correct
20 Correct 61 ms 7540 KB Output is correct
21 Correct 58 ms 7452 KB Output is correct
22 Correct 61 ms 7584 KB Output is correct
23 Correct 89 ms 7928 KB Output is correct
24 Correct 73 ms 7800 KB Output is correct
25 Correct 54 ms 21208 KB Output is correct
26 Correct 48 ms 34896 KB Output is correct
27 Correct 109 ms 17960 KB Output is correct
28 Correct 158 ms 69736 KB Output is correct
29 Correct 174 ms 67252 KB Output is correct
30 Correct 122 ms 18048 KB Output is correct
31 Correct 114 ms 18000 KB Output is correct
32 Correct 116 ms 18208 KB Output is correct
33 Correct 135 ms 17496 KB Output is correct
34 Correct 218 ms 27880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 428 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 468 KB Output is correct
35 Correct 1 ms 468 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 60 ms 7452 KB Output is correct
40 Correct 61 ms 7540 KB Output is correct
41 Correct 58 ms 7452 KB Output is correct
42 Correct 61 ms 7584 KB Output is correct
43 Correct 89 ms 7928 KB Output is correct
44 Correct 73 ms 7800 KB Output is correct
45 Correct 54 ms 21208 KB Output is correct
46 Correct 48 ms 34896 KB Output is correct
47 Correct 109 ms 17960 KB Output is correct
48 Correct 158 ms 69736 KB Output is correct
49 Correct 174 ms 67252 KB Output is correct
50 Correct 122 ms 18048 KB Output is correct
51 Correct 114 ms 18000 KB Output is correct
52 Correct 116 ms 18208 KB Output is correct
53 Correct 135 ms 17496 KB Output is correct
54 Correct 218 ms 27880 KB Output is correct
55 Correct 10 ms 1464 KB Output is correct
56 Correct 5 ms 1108 KB Output is correct
57 Correct 40 ms 9020 KB Output is correct
58 Correct 36 ms 8708 KB Output is correct
59 Correct 77 ms 34852 KB Output is correct
60 Correct 162 ms 67916 KB Output is correct
61 Correct 135 ms 19480 KB Output is correct
62 Correct 118 ms 18060 KB Output is correct
63 Correct 151 ms 18216 KB Output is correct
64 Correct 294 ms 24724 KB Output is correct
65 Correct 276 ms 28156 KB Output is correct
66 Correct 190 ms 61600 KB Output is correct
67 Correct 85 ms 18556 KB Output is correct
68 Correct 188 ms 26652 KB Output is correct
69 Correct 265 ms 30028 KB Output is correct
70 Correct 187 ms 25656 KB Output is correct