# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
600992 |
2022-07-21T09:52:10 Z |
Meloric |
Race (IOI11_race) |
C++14 |
|
630 ms |
114120 KB |
#pragma GCC optimize("O3")
#include "race.h"
#include <bits/stdc++.h>
#define pb push_back
#define int int64_t
#define pii pair<int, int>
#define X first
#define Y second
#define all(x) (x).begin(),(x).end()
#define lb lower_bound
#define ub upper_bound
#define speSet pair<pii, set<pii>>
using namespace std;
const int inf = 1e18;
void p(auto A){
for(auto e : A)cout << e << ' ';
cout << '\n';
}
struct special_set{
/*set<pii> S;
pii delta = {0, 0};
void insert(pii e){
S.insert({e.X-delta.X, e.Y-delta.Y});
}
void update(pii dx){
delta.X+=dx.X;
delta.Y+=dx.Y;
}
int find(int x){
x-=delta.X;
if(S.lb({x, -inf}) == S.end())return inf;
if(S.lb({x, -inf})->X != x)return inf;
return S.lb({x, -inf})->Y+delta.Y;
}
pii pop(){
pii ret = *S.begin();
S.erase(S.begin());
ret.X+=delta.X;
ret.Y+=delta.Y;
return ret;
}
int size(){
return S.size();
}
void p(){
//for(auto [e, f] : S)cout << e+delta.X << ' '<< f+delta.Y << endl;
}
*/
};
signed best_path(signed N, signed K, signed H[][2], signed L[])
{
int n = N;
int k = K;
vector<vector<pii>> g(n, vector<pii>());
for(int i = 0; i< n-1; i++){
int c = H[i][0];
int d = H[i][1];
int w = L[i];
g[c].pb({d, w});
g[d].pb({c, w});
}
int ret = inf;
vector<speSet>A(n);
auto dfs = [&](auto&&self, int u, int p)->void{
A[u].Y.insert({0, 0});
for(auto [v, w] : g[u])if(v!=p){
self(self, v, u);
A[v].X.X+=w;
A[v].X.Y+=1;
if(A[u].Y.size() < A[v].Y.size())swap(A[u], A[v]);
auto [vx, vy] = A[v].X;
auto [ux, uy] = A[u].X;
for(auto [ex, ey] : A[v].Y){
ex+=vx; ey+=vy;
auto it = A[u].Y.lb({k-ex-ux, -inf});
if(it != A[u].Y.end() && it->X+ux == k-ex)ret=min(ret, ey+it->Y+uy);
}
for(auto [ex, ey] : A[v].Y){
ex = ex+vx-ux;
ey = ey+vy-uy;
A[u].Y.insert({ex, ey});
}
}
};
/*
auto dfs = [&](auto&& self, int u, int p)->special_set*{
//cout << u << endl;
special_set* S = new special_set();
S->insert({0, 0});
vector<pii> V;
for(auto [v, w] : g[u])if(v!=p){
special_set* O = self(self, v, u);
O->update(make_pair(w, 1ll));
if(S->size() < O->size())swap(S, O);
while(O->size()){
pii e = O->pop();
//cout << u << ' '<< e.X << ' '<< e.Y << ' ' << endl;
ret = min(ret, e.Y+S->find(k-e.X));
if(e.X > k)continue;
V.pb(e);
//S.insert(e);
}
for(auto e : V)S->insert(e);
}
return S;
};
*/
dfs(dfs, 0, 0);
if(ret == inf)return -1;
return ret;
}
/*
void solve(){
signed N, K, H[100][2], L[100];
cin >> N >> K;
for(int i = 0; i< N-1; i++){
cin >> H[i][0] >> H[i][1] >> L[i];
}
cout << best_path(N, K, H, L);
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
//cin >> t;
while(t--)solve();
}*/
Compilation message
race.cpp:20:8: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
20 | void p(auto A){
| ^~~~
race.cpp: In lambda function:
race.cpp:74:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
74 | for(auto [v, w] : g[u])if(v!=p){
| ^
race.cpp:79:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
79 | auto [vx, vy] = A[v].X;
| ^
race.cpp:80:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
80 | auto [ux, uy] = A[u].X;
| ^
race.cpp:81:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
81 | for(auto [ex, ey] : A[v].Y){
| ^
race.cpp:86:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
86 | for(auto [ex, ey] : A[v].Y){
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
304 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
308 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
304 KB |
Output is correct |
13 |
Correct |
1 ms |
312 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
304 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
308 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
304 KB |
Output is correct |
13 |
Correct |
1 ms |
312 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
596 KB |
Output is correct |
22 |
Correct |
2 ms |
724 KB |
Output is correct |
23 |
Correct |
1 ms |
596 KB |
Output is correct |
24 |
Correct |
2 ms |
596 KB |
Output is correct |
25 |
Correct |
2 ms |
708 KB |
Output is correct |
26 |
Correct |
2 ms |
596 KB |
Output is correct |
27 |
Correct |
2 ms |
468 KB |
Output is correct |
28 |
Correct |
2 ms |
704 KB |
Output is correct |
29 |
Correct |
2 ms |
596 KB |
Output is correct |
30 |
Correct |
2 ms |
700 KB |
Output is correct |
31 |
Correct |
2 ms |
596 KB |
Output is correct |
32 |
Correct |
2 ms |
596 KB |
Output is correct |
33 |
Correct |
2 ms |
704 KB |
Output is correct |
34 |
Correct |
1 ms |
596 KB |
Output is correct |
35 |
Correct |
1 ms |
596 KB |
Output is correct |
36 |
Correct |
2 ms |
640 KB |
Output is correct |
37 |
Correct |
1 ms |
596 KB |
Output is correct |
38 |
Correct |
2 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
304 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
308 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
304 KB |
Output is correct |
13 |
Correct |
1 ms |
312 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
180 ms |
36580 KB |
Output is correct |
20 |
Correct |
217 ms |
36512 KB |
Output is correct |
21 |
Correct |
226 ms |
35880 KB |
Output is correct |
22 |
Correct |
208 ms |
34232 KB |
Output is correct |
23 |
Correct |
277 ms |
48848 KB |
Output is correct |
24 |
Correct |
167 ms |
34852 KB |
Output is correct |
25 |
Correct |
174 ms |
36896 KB |
Output is correct |
26 |
Correct |
100 ms |
39120 KB |
Output is correct |
27 |
Correct |
262 ms |
53516 KB |
Output is correct |
28 |
Correct |
407 ms |
77088 KB |
Output is correct |
29 |
Correct |
389 ms |
76376 KB |
Output is correct |
30 |
Correct |
251 ms |
53604 KB |
Output is correct |
31 |
Correct |
281 ms |
53392 KB |
Output is correct |
32 |
Correct |
325 ms |
53500 KB |
Output is correct |
33 |
Correct |
301 ms |
55148 KB |
Output is correct |
34 |
Correct |
388 ms |
87052 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
304 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
308 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
304 KB |
Output is correct |
13 |
Correct |
1 ms |
312 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
596 KB |
Output is correct |
22 |
Correct |
2 ms |
724 KB |
Output is correct |
23 |
Correct |
1 ms |
596 KB |
Output is correct |
24 |
Correct |
2 ms |
596 KB |
Output is correct |
25 |
Correct |
2 ms |
708 KB |
Output is correct |
26 |
Correct |
2 ms |
596 KB |
Output is correct |
27 |
Correct |
2 ms |
468 KB |
Output is correct |
28 |
Correct |
2 ms |
704 KB |
Output is correct |
29 |
Correct |
2 ms |
596 KB |
Output is correct |
30 |
Correct |
2 ms |
700 KB |
Output is correct |
31 |
Correct |
2 ms |
596 KB |
Output is correct |
32 |
Correct |
2 ms |
596 KB |
Output is correct |
33 |
Correct |
2 ms |
704 KB |
Output is correct |
34 |
Correct |
1 ms |
596 KB |
Output is correct |
35 |
Correct |
1 ms |
596 KB |
Output is correct |
36 |
Correct |
2 ms |
640 KB |
Output is correct |
37 |
Correct |
1 ms |
596 KB |
Output is correct |
38 |
Correct |
2 ms |
596 KB |
Output is correct |
39 |
Correct |
180 ms |
36580 KB |
Output is correct |
40 |
Correct |
217 ms |
36512 KB |
Output is correct |
41 |
Correct |
226 ms |
35880 KB |
Output is correct |
42 |
Correct |
208 ms |
34232 KB |
Output is correct |
43 |
Correct |
277 ms |
48848 KB |
Output is correct |
44 |
Correct |
167 ms |
34852 KB |
Output is correct |
45 |
Correct |
174 ms |
36896 KB |
Output is correct |
46 |
Correct |
100 ms |
39120 KB |
Output is correct |
47 |
Correct |
262 ms |
53516 KB |
Output is correct |
48 |
Correct |
407 ms |
77088 KB |
Output is correct |
49 |
Correct |
389 ms |
76376 KB |
Output is correct |
50 |
Correct |
251 ms |
53604 KB |
Output is correct |
51 |
Correct |
281 ms |
53392 KB |
Output is correct |
52 |
Correct |
325 ms |
53500 KB |
Output is correct |
53 |
Correct |
301 ms |
55148 KB |
Output is correct |
54 |
Correct |
388 ms |
87052 KB |
Output is correct |
55 |
Correct |
17 ms |
4660 KB |
Output is correct |
56 |
Correct |
15 ms |
3388 KB |
Output is correct |
57 |
Correct |
134 ms |
31348 KB |
Output is correct |
58 |
Correct |
65 ms |
21852 KB |
Output is correct |
59 |
Correct |
90 ms |
39624 KB |
Output is correct |
60 |
Correct |
366 ms |
78668 KB |
Output is correct |
61 |
Correct |
349 ms |
61296 KB |
Output is correct |
62 |
Correct |
246 ms |
55592 KB |
Output is correct |
63 |
Correct |
337 ms |
55652 KB |
Output is correct |
64 |
Correct |
630 ms |
114120 KB |
Output is correct |
65 |
Correct |
560 ms |
105656 KB |
Output is correct |
66 |
Correct |
358 ms |
77220 KB |
Output is correct |
67 |
Correct |
197 ms |
45544 KB |
Output is correct |
68 |
Correct |
467 ms |
70212 KB |
Output is correct |
69 |
Correct |
391 ms |
75932 KB |
Output is correct |
70 |
Correct |
363 ms |
67128 KB |
Output is correct |