Submission #251399

# Submission time Handle Problem Language Result Execution time Memory
251399 2020-07-21T06:52:26 Z leaked Race (IOI11_race) C++14
100 / 100
544 ms 102264 KB
#include<bits/stdc++.h>
#include "race.h"
using namespace std;
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
//////
//    #pragma GCC optimize("unroll-loops")
//    #pragma GCC optimize("Ofast")
//    #pragma GCC optimize("-O3")
//    #pragma GCC optimize("no-stack-protector")
//    #pragma GCC optimize("fast-math")
//////#define LOCAL
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cout << *x, 0);
sim > char dud(...);
struct debug {
#ifndef LOCAL
~debug() { cout << endl; }
eni(!=) cout << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fi first
#define f first
#define se second
#define s second
#define vi_a vector<int>a;
#define p_b push_back
////////////////////////////////???????????????CHECK THIS OUT???????????????//////////////////////////////
#define ll long long
//#define ull unsigned long long
typedef unsigned long long ull;
////////////////////////////////???????????????CHECK THIS OUT???????????????//////////////////////////////
#define ld long double
#define pll pair<ll,ll>
#define pii pair<int,int>
#define m_p make_pair
#define fast_io cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
#define all(x) x.begin(),x.end()
#define getfiles    ifstream cin("input.txt");ofstream cout("output.txt");
#define pw(x) (1ll << x)
#define sz(x) (ll)x.size()
#define endl "\n"
#define rall(x) x.rbegin(),x.rend()
#define len(a) (ll)a.size()
#define rep(x,l,r) for(ll x=l;x<r;x++)

//using namespace __gnu_pbds;
ld eps = (ld)1 / 1e6;
const ld pi=3.14159265359;
ll inf = 1e18,mod1=1e9+7;
ll sqr(ll a) { return a * a; }
ll qb(ll a) { return a * a * a; }
ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
void binary(ll val,int to) {for(int i=0;i<to;i++) cerr<<(pw(i) & val ? 1 : 0); cerr<<endl;}
ll binpow(ll a, ll b, ll mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; }
ll binmult(ll a, ll b, ll mod) { return b ? (b % 2 ? (2 * binmult(a, b / 2, mod) + a) % mod : (2 * binmult(a, b / 2, mod)) % mod) : 0; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const ll R=1e4;
const ll tx[4]={1,0,-1,0};
const ll ty[4]={0,1,0,-1};
const char rev_to[4]={'E','W','N','S'};
const int Nmax=2e5+100;
const int M=999999937;
const int pp=73;
//typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> st;
void bad(){
    cout<<-1;
    exit(0);
}
ll n,sz[Nmax],h[Nmax],k,a[Nmax];
ll s[Nmax];
vector<pll>g[Nmax];
set<pll>* vec[Nmax];
void prec(ll v,ll p,ll gl,ll ss){
    sz[v]=1;
    h[v]=gl;
    s[v]=ss;
    for(auto &z : g[v]){
        if(z.f==p) continue;
        prec(z.f,v,gl+1,z.s+ss);
        sz[v]+=sz[z.f];
    }
//    debug()<<imie(h[v])<<imie(s[v]);
}
ll ans=2e9;
void dfs(ll v,ll p){
    ll big=-1;
    for(auto &u : g[v]){
        if(u.f==p) continue;
        if(big==-1 || sz[u.f]>sz[big]) big=u.f;
    }
    for(auto &u : g[v]){
        if(u.f==p || u.f==big) continue;
        dfs(u.f,v);
    }
    if(big==-1){
        vec[v]=new set<pll>();
    }else{
        dfs(big,v);vec[v]=vec[big];
    }
    vec[v]->insert({s[v],h[v]});
    for(auto &u : g[v]){
        if(u.f==p || u.f==big) continue;
        for(auto &z : *vec[u.f]){
            if(z.f-s[v]>k) continue;
            auto it=vec[v]->lower_bound(m_p(s[v]+(k-(z.f-s[v])),(ll)-2e9));
            if(it!=vec[v]->end()){
                if(it->f+z.f-2*s[v]==k){
                    ans=min(ans,it->s+z.s-2*h[v]);
                }
            }
        }
        vec[v]->insert(all((*vec[u.f])));
    }
//    debug()<<imie(*vec[v]);
    auto it=vec[v]->lower_bound(m_p(s[v]+k,(ll)-2e9));
    if(it!=vec[v]->end()){
        if(it->f==s[v]+k){
            ans=min(ans,it->s-h[v]);
        }
    }

}
int best_path(int N,int K,int H[][2],int L[]){
    fast_io;
    n=N,k=K;
    for(int i=0;i<n-1;i++){
        g[H[i][0]].p_b(m_p(H[i][1],L[i]));
        g[H[i][1]].p_b({H[i][0],L[i]});
    }
    prec(0,0,0,0);
    dfs(0,0);
    if(ans==2e9) ans=-1;
    return int(ans);
}
/*


*/
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5120 KB Output is correct
2 Correct 3 ms 5120 KB Output is correct
3 Correct 3 ms 5120 KB Output is correct
4 Correct 3 ms 5120 KB Output is correct
5 Correct 3 ms 5120 KB Output is correct
6 Correct 3 ms 5120 KB Output is correct
7 Correct 4 ms 5120 KB Output is correct
8 Correct 3 ms 5120 KB Output is correct
9 Correct 3 ms 5120 KB Output is correct
10 Correct 4 ms 5120 KB Output is correct
11 Correct 5 ms 5120 KB Output is correct
12 Correct 4 ms 5120 KB Output is correct
13 Correct 4 ms 5120 KB Output is correct
14 Correct 4 ms 5120 KB Output is correct
15 Correct 3 ms 5120 KB Output is correct
16 Correct 3 ms 5120 KB Output is correct
17 Correct 4 ms 5120 KB Output is correct
18 Correct 3 ms 5120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5120 KB Output is correct
2 Correct 3 ms 5120 KB Output is correct
3 Correct 3 ms 5120 KB Output is correct
4 Correct 3 ms 5120 KB Output is correct
5 Correct 3 ms 5120 KB Output is correct
6 Correct 3 ms 5120 KB Output is correct
7 Correct 4 ms 5120 KB Output is correct
8 Correct 3 ms 5120 KB Output is correct
9 Correct 3 ms 5120 KB Output is correct
10 Correct 4 ms 5120 KB Output is correct
11 Correct 5 ms 5120 KB Output is correct
12 Correct 4 ms 5120 KB Output is correct
13 Correct 4 ms 5120 KB Output is correct
14 Correct 4 ms 5120 KB Output is correct
15 Correct 3 ms 5120 KB Output is correct
16 Correct 3 ms 5120 KB Output is correct
17 Correct 4 ms 5120 KB Output is correct
18 Correct 3 ms 5120 KB Output is correct
19 Correct 4 ms 5120 KB Output is correct
20 Correct 5 ms 5120 KB Output is correct
21 Correct 6 ms 5376 KB Output is correct
22 Correct 5 ms 5376 KB Output is correct
23 Correct 5 ms 5376 KB Output is correct
24 Correct 6 ms 5376 KB Output is correct
25 Correct 4 ms 5376 KB Output is correct
26 Correct 5 ms 5376 KB Output is correct
27 Correct 4 ms 5248 KB Output is correct
28 Correct 7 ms 5376 KB Output is correct
29 Correct 5 ms 5376 KB Output is correct
30 Correct 6 ms 5376 KB Output is correct
31 Correct 5 ms 5376 KB Output is correct
32 Correct 4 ms 5376 KB Output is correct
33 Correct 5 ms 5376 KB Output is correct
34 Correct 4 ms 5248 KB Output is correct
35 Correct 4 ms 5248 KB Output is correct
36 Correct 4 ms 5376 KB Output is correct
37 Correct 4 ms 5248 KB Output is correct
38 Correct 4 ms 5376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5120 KB Output is correct
2 Correct 3 ms 5120 KB Output is correct
3 Correct 3 ms 5120 KB Output is correct
4 Correct 3 ms 5120 KB Output is correct
5 Correct 3 ms 5120 KB Output is correct
6 Correct 3 ms 5120 KB Output is correct
7 Correct 4 ms 5120 KB Output is correct
8 Correct 3 ms 5120 KB Output is correct
9 Correct 3 ms 5120 KB Output is correct
10 Correct 4 ms 5120 KB Output is correct
11 Correct 5 ms 5120 KB Output is correct
12 Correct 4 ms 5120 KB Output is correct
13 Correct 4 ms 5120 KB Output is correct
14 Correct 4 ms 5120 KB Output is correct
15 Correct 3 ms 5120 KB Output is correct
16 Correct 3 ms 5120 KB Output is correct
17 Correct 4 ms 5120 KB Output is correct
18 Correct 3 ms 5120 KB Output is correct
19 Correct 161 ms 34296 KB Output is correct
20 Correct 158 ms 34168 KB Output is correct
21 Correct 182 ms 33880 KB Output is correct
22 Correct 186 ms 33528 KB Output is correct
23 Correct 210 ms 49144 KB Output is correct
24 Correct 152 ms 39416 KB Output is correct
25 Correct 169 ms 32888 KB Output is correct
26 Correct 104 ms 37368 KB Output is correct
27 Correct 295 ms 49528 KB Output is correct
28 Correct 359 ms 69880 KB Output is correct
29 Correct 344 ms 68600 KB Output is correct
30 Correct 289 ms 49528 KB Output is correct
31 Correct 294 ms 49400 KB Output is correct
32 Correct 319 ms 49784 KB Output is correct
33 Correct 317 ms 38904 KB Output is correct
34 Correct 348 ms 71800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5120 KB Output is correct
2 Correct 3 ms 5120 KB Output is correct
3 Correct 3 ms 5120 KB Output is correct
4 Correct 3 ms 5120 KB Output is correct
5 Correct 3 ms 5120 KB Output is correct
6 Correct 3 ms 5120 KB Output is correct
7 Correct 4 ms 5120 KB Output is correct
8 Correct 3 ms 5120 KB Output is correct
9 Correct 3 ms 5120 KB Output is correct
10 Correct 4 ms 5120 KB Output is correct
11 Correct 5 ms 5120 KB Output is correct
12 Correct 4 ms 5120 KB Output is correct
13 Correct 4 ms 5120 KB Output is correct
14 Correct 4 ms 5120 KB Output is correct
15 Correct 3 ms 5120 KB Output is correct
16 Correct 3 ms 5120 KB Output is correct
17 Correct 4 ms 5120 KB Output is correct
18 Correct 3 ms 5120 KB Output is correct
19 Correct 4 ms 5120 KB Output is correct
20 Correct 5 ms 5120 KB Output is correct
21 Correct 6 ms 5376 KB Output is correct
22 Correct 5 ms 5376 KB Output is correct
23 Correct 5 ms 5376 KB Output is correct
24 Correct 6 ms 5376 KB Output is correct
25 Correct 4 ms 5376 KB Output is correct
26 Correct 5 ms 5376 KB Output is correct
27 Correct 4 ms 5248 KB Output is correct
28 Correct 7 ms 5376 KB Output is correct
29 Correct 5 ms 5376 KB Output is correct
30 Correct 6 ms 5376 KB Output is correct
31 Correct 5 ms 5376 KB Output is correct
32 Correct 4 ms 5376 KB Output is correct
33 Correct 5 ms 5376 KB Output is correct
34 Correct 4 ms 5248 KB Output is correct
35 Correct 4 ms 5248 KB Output is correct
36 Correct 4 ms 5376 KB Output is correct
37 Correct 4 ms 5248 KB Output is correct
38 Correct 4 ms 5376 KB Output is correct
39 Correct 161 ms 34296 KB Output is correct
40 Correct 158 ms 34168 KB Output is correct
41 Correct 182 ms 33880 KB Output is correct
42 Correct 186 ms 33528 KB Output is correct
43 Correct 210 ms 49144 KB Output is correct
44 Correct 152 ms 39416 KB Output is correct
45 Correct 169 ms 32888 KB Output is correct
46 Correct 104 ms 37368 KB Output is correct
47 Correct 295 ms 49528 KB Output is correct
48 Correct 359 ms 69880 KB Output is correct
49 Correct 344 ms 68600 KB Output is correct
50 Correct 289 ms 49528 KB Output is correct
51 Correct 294 ms 49400 KB Output is correct
52 Correct 319 ms 49784 KB Output is correct
53 Correct 317 ms 38904 KB Output is correct
54 Correct 348 ms 71800 KB Output is correct
55 Correct 17 ms 8832 KB Output is correct
56 Correct 12 ms 7552 KB Output is correct
57 Correct 89 ms 31480 KB Output is correct
58 Correct 65 ms 27880 KB Output is correct
59 Correct 98 ms 37368 KB Output is correct
60 Correct 296 ms 68984 KB Output is correct
61 Correct 311 ms 55416 KB Output is correct
62 Correct 286 ms 49528 KB Output is correct
63 Correct 369 ms 49784 KB Output is correct
64 Correct 490 ms 102264 KB Output is correct
65 Correct 544 ms 97528 KB Output is correct
66 Correct 342 ms 65528 KB Output is correct
67 Correct 251 ms 51420 KB Output is correct
68 Correct 383 ms 67976 KB Output is correct
69 Correct 453 ms 68856 KB Output is correct
70 Correct 410 ms 65272 KB Output is correct