# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
139433 |
2019-07-31T17:13:58 Z |
claudy |
Race (IOI11_race) |
C++14 |
|
597 ms |
45840 KB |
# include "race.h"
//# pragma GCC optimize("Ofast,no-stack-protector")
//# pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
# pragma GCC optimize("Ofast")
# pragma GCC optimization ("unroll-loops")
# include "bits/stdc++.h"
/*
# include <ext/pb_ds/tree_policy.hpp>
# include <ext/pb_ds/assoc_container.hpp>
# include <ext/rope>
*/
std::pair<int,int> DR[] = {{-1,0},{0,1},{1,0},{0,-1},{-1,1},{-1,-1},{1,1},{1,-1}};
# define ll long long
# define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
# define rc(s) return cout << s,0
# define rcg(s) cout << s;exit(0)
# define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
# define db(x) cerr << #x << " = " << x << '\n'
# define pb push_back
# define mp make_pair
# define all(s) s.begin(),s.end()
# define sz(x) (int)((x).size())
# define int ll
using namespace std;
int dep[1 << 17],dep2[1 << 17],s[1 << 17],x,ans = 1e18,n,k;
vector<pair<int,int>>vec[1 << 17];
map<int,multiset<int>>ms;
void pre(int nod,int par,int val)
{
dep[nod] = dep[par] + val;
dep2[nod] = dep2[par] + 1;
s[nod] = 1;
for(auto it : vec[nod])
{
if(it.first != par)
{
pre(it.first,nod,it.second);
s[nod] += s[it.first];
}
}
}
void add1_node(int nod,int gg)
{
if(sz(ms[2 * gg + k - dep[nod]]))
{
x = min(x,dep2[nod] + *(ms[2 * gg + k - dep[nod]].begin()));
}
}
void add2_node(int nod,int gg)
{
ms[dep[nod]].insert(dep2[nod]);
}
void add1(int nod,int par,int gg)
{
add1_node(nod,gg);
for(auto it : vec[nod])
{
if(it.first != par)
{
add1(it.first,nod,gg);
}
}
}
void add2(int nod,int par,int gg)
{
add2_node(nod,gg);
for(auto it : vec[nod])
{
if(it.first != par)
{
add2(it.first,nod,gg);
}
}
}
void del_node(int nod)
{
ms[dep[nod]].erase(ms[dep[nod]].find(dep2[nod]));
}
void del(int nod,int par)
{
del_node(nod);
for(auto it : vec[nod])
{
if(it.first != par)
{
del(it.first,nod);
}
}
}
void dfs(int nod,int par,bool keep)
{
pair<int,int>mx = mp(-1,-1);
for(auto it : vec[nod])
{
if(it.first != par)
{
mx = max(mx,mp(s[it.first],it.first));
}
}
for(auto it : vec[nod])
{
if(it.first != par && it.first != mx.second)
{
dfs(it.first,nod,0);
}
}
if(mx.second != -1) dfs(mx.second,nod,1);
x = 1e18;
add1_node(nod,dep[nod]);
add2_node(nod,dep[nod]);
for(auto it : vec[nod])
{
if(it.first != par && it.first != mx.second)
{
add1(it.first,nod,dep[nod]);
add2(it.first,nod,dep[nod]);
}
}
//cout << nod << ' ' << x << ' ' << x - 2 * dep2[nod] << '\n';
if(x != 1e18) ans = min(ans,x - 2 * dep2[nod]);
if(keep) return ;
del(nod,par);
}
# undef int
int best_path(int N, int K, int H[][2], int L[])
{
# define int ll
k = K;
n = N;
for(int i = 0;i < n - 1;i++)
{
vec[H[i][0]].pb(mp(H[i][1],L[i]));
vec[H[i][1]].pb(mp(H[i][0],L[i]));
}
pre(0,0,0);
dfs(0,0,1);
if(ans == 1e18) return -1;
else return ans;
}
Compilation message
race.cpp:5:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
# pragma GCC optimization ("unroll-loops")
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
3448 KB |
Output is correct |
2 |
Correct |
5 ms |
3448 KB |
Output is correct |
3 |
Correct |
5 ms |
3448 KB |
Output is correct |
4 |
Correct |
5 ms |
3448 KB |
Output is correct |
5 |
Correct |
5 ms |
3448 KB |
Output is correct |
6 |
Correct |
5 ms |
3448 KB |
Output is correct |
7 |
Correct |
5 ms |
3448 KB |
Output is correct |
8 |
Correct |
5 ms |
3448 KB |
Output is correct |
9 |
Correct |
5 ms |
3448 KB |
Output is correct |
10 |
Correct |
5 ms |
3448 KB |
Output is correct |
11 |
Correct |
5 ms |
3448 KB |
Output is correct |
12 |
Correct |
5 ms |
3448 KB |
Output is correct |
13 |
Correct |
5 ms |
3448 KB |
Output is correct |
14 |
Correct |
5 ms |
3448 KB |
Output is correct |
15 |
Correct |
5 ms |
3448 KB |
Output is correct |
16 |
Correct |
5 ms |
3448 KB |
Output is correct |
17 |
Correct |
5 ms |
3448 KB |
Output is correct |
18 |
Correct |
5 ms |
3448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
3448 KB |
Output is correct |
2 |
Correct |
5 ms |
3448 KB |
Output is correct |
3 |
Correct |
5 ms |
3448 KB |
Output is correct |
4 |
Correct |
5 ms |
3448 KB |
Output is correct |
5 |
Correct |
5 ms |
3448 KB |
Output is correct |
6 |
Correct |
5 ms |
3448 KB |
Output is correct |
7 |
Correct |
5 ms |
3448 KB |
Output is correct |
8 |
Correct |
5 ms |
3448 KB |
Output is correct |
9 |
Correct |
5 ms |
3448 KB |
Output is correct |
10 |
Correct |
5 ms |
3448 KB |
Output is correct |
11 |
Correct |
5 ms |
3448 KB |
Output is correct |
12 |
Correct |
5 ms |
3448 KB |
Output is correct |
13 |
Correct |
5 ms |
3448 KB |
Output is correct |
14 |
Correct |
5 ms |
3448 KB |
Output is correct |
15 |
Correct |
5 ms |
3448 KB |
Output is correct |
16 |
Correct |
5 ms |
3448 KB |
Output is correct |
17 |
Correct |
5 ms |
3448 KB |
Output is correct |
18 |
Correct |
5 ms |
3448 KB |
Output is correct |
19 |
Correct |
5 ms |
3448 KB |
Output is correct |
20 |
Correct |
5 ms |
3448 KB |
Output is correct |
21 |
Correct |
7 ms |
3704 KB |
Output is correct |
22 |
Correct |
8 ms |
3936 KB |
Output is correct |
23 |
Correct |
8 ms |
3960 KB |
Output is correct |
24 |
Correct |
8 ms |
3832 KB |
Output is correct |
25 |
Correct |
8 ms |
3960 KB |
Output is correct |
26 |
Correct |
8 ms |
3960 KB |
Output is correct |
27 |
Correct |
6 ms |
3576 KB |
Output is correct |
28 |
Correct |
8 ms |
3960 KB |
Output is correct |
29 |
Correct |
8 ms |
3960 KB |
Output is correct |
30 |
Correct |
8 ms |
3960 KB |
Output is correct |
31 |
Correct |
8 ms |
3960 KB |
Output is correct |
32 |
Correct |
8 ms |
3960 KB |
Output is correct |
33 |
Correct |
8 ms |
4088 KB |
Output is correct |
34 |
Correct |
7 ms |
3832 KB |
Output is correct |
35 |
Correct |
6 ms |
3832 KB |
Output is correct |
36 |
Correct |
6 ms |
3832 KB |
Output is correct |
37 |
Correct |
6 ms |
3832 KB |
Output is correct |
38 |
Correct |
7 ms |
3832 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
3448 KB |
Output is correct |
2 |
Correct |
5 ms |
3448 KB |
Output is correct |
3 |
Correct |
5 ms |
3448 KB |
Output is correct |
4 |
Correct |
5 ms |
3448 KB |
Output is correct |
5 |
Correct |
5 ms |
3448 KB |
Output is correct |
6 |
Correct |
5 ms |
3448 KB |
Output is correct |
7 |
Correct |
5 ms |
3448 KB |
Output is correct |
8 |
Correct |
5 ms |
3448 KB |
Output is correct |
9 |
Correct |
5 ms |
3448 KB |
Output is correct |
10 |
Correct |
5 ms |
3448 KB |
Output is correct |
11 |
Correct |
5 ms |
3448 KB |
Output is correct |
12 |
Correct |
5 ms |
3448 KB |
Output is correct |
13 |
Correct |
5 ms |
3448 KB |
Output is correct |
14 |
Correct |
5 ms |
3448 KB |
Output is correct |
15 |
Correct |
5 ms |
3448 KB |
Output is correct |
16 |
Correct |
5 ms |
3448 KB |
Output is correct |
17 |
Correct |
5 ms |
3448 KB |
Output is correct |
18 |
Correct |
5 ms |
3448 KB |
Output is correct |
19 |
Correct |
447 ms |
18284 KB |
Output is correct |
20 |
Correct |
447 ms |
18120 KB |
Output is correct |
21 |
Correct |
461 ms |
18328 KB |
Output is correct |
22 |
Correct |
447 ms |
18196 KB |
Output is correct |
23 |
Correct |
597 ms |
18808 KB |
Output is correct |
24 |
Correct |
367 ms |
18060 KB |
Output is correct |
25 |
Correct |
181 ms |
33528 KB |
Output is correct |
26 |
Correct |
98 ms |
45840 KB |
Output is correct |
27 |
Runtime error |
105 ms |
24952 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
3448 KB |
Output is correct |
2 |
Correct |
5 ms |
3448 KB |
Output is correct |
3 |
Correct |
5 ms |
3448 KB |
Output is correct |
4 |
Correct |
5 ms |
3448 KB |
Output is correct |
5 |
Correct |
5 ms |
3448 KB |
Output is correct |
6 |
Correct |
5 ms |
3448 KB |
Output is correct |
7 |
Correct |
5 ms |
3448 KB |
Output is correct |
8 |
Correct |
5 ms |
3448 KB |
Output is correct |
9 |
Correct |
5 ms |
3448 KB |
Output is correct |
10 |
Correct |
5 ms |
3448 KB |
Output is correct |
11 |
Correct |
5 ms |
3448 KB |
Output is correct |
12 |
Correct |
5 ms |
3448 KB |
Output is correct |
13 |
Correct |
5 ms |
3448 KB |
Output is correct |
14 |
Correct |
5 ms |
3448 KB |
Output is correct |
15 |
Correct |
5 ms |
3448 KB |
Output is correct |
16 |
Correct |
5 ms |
3448 KB |
Output is correct |
17 |
Correct |
5 ms |
3448 KB |
Output is correct |
18 |
Correct |
5 ms |
3448 KB |
Output is correct |
19 |
Correct |
5 ms |
3448 KB |
Output is correct |
20 |
Correct |
5 ms |
3448 KB |
Output is correct |
21 |
Correct |
7 ms |
3704 KB |
Output is correct |
22 |
Correct |
8 ms |
3936 KB |
Output is correct |
23 |
Correct |
8 ms |
3960 KB |
Output is correct |
24 |
Correct |
8 ms |
3832 KB |
Output is correct |
25 |
Correct |
8 ms |
3960 KB |
Output is correct |
26 |
Correct |
8 ms |
3960 KB |
Output is correct |
27 |
Correct |
6 ms |
3576 KB |
Output is correct |
28 |
Correct |
8 ms |
3960 KB |
Output is correct |
29 |
Correct |
8 ms |
3960 KB |
Output is correct |
30 |
Correct |
8 ms |
3960 KB |
Output is correct |
31 |
Correct |
8 ms |
3960 KB |
Output is correct |
32 |
Correct |
8 ms |
3960 KB |
Output is correct |
33 |
Correct |
8 ms |
4088 KB |
Output is correct |
34 |
Correct |
7 ms |
3832 KB |
Output is correct |
35 |
Correct |
6 ms |
3832 KB |
Output is correct |
36 |
Correct |
6 ms |
3832 KB |
Output is correct |
37 |
Correct |
6 ms |
3832 KB |
Output is correct |
38 |
Correct |
7 ms |
3832 KB |
Output is correct |
39 |
Correct |
447 ms |
18284 KB |
Output is correct |
40 |
Correct |
447 ms |
18120 KB |
Output is correct |
41 |
Correct |
461 ms |
18328 KB |
Output is correct |
42 |
Correct |
447 ms |
18196 KB |
Output is correct |
43 |
Correct |
597 ms |
18808 KB |
Output is correct |
44 |
Correct |
367 ms |
18060 KB |
Output is correct |
45 |
Correct |
181 ms |
33528 KB |
Output is correct |
46 |
Correct |
98 ms |
45840 KB |
Output is correct |
47 |
Runtime error |
105 ms |
24952 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
48 |
Halted |
0 ms |
0 KB |
- |