답안 #199941

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
199941 2020-02-04T08:42:54 Z sans 경주 (Race) (IOI11_race) C++14
100 / 100
509 ms 104312 KB
#include <bits/stdc++.h>
//#include "race.h"
using namespace std;

#define sp ' '
#define endl '\n'
#define st first
#define nd second
#define sz(x) ((long long int)x.size())
#define pb push_back
#define pob pop_back
#define mp make_pair
#define forn(YY, yy) for(long long int yy = 0; yy < YY; ++yy)
#define prn(XX) cout << XX << '\n'
#define prs(XX) cout << XX << " "
#define TEST cout << "TEST\n";

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;

const long long int MOD = 1e9 + 7;
const long long int INF = 2e9 + 13;
const long long int mINF = -2e9 - 13;
const double PI = acos(-1.0);
const double EPS = 1e-9;

ll mx(ll x, ll y){ return (x>y?x:y); }
ll mn(ll x, ll y){ return (x<y?x:y); }

void max_self(ll &x, ll y){ x = mx(x, y); }
void min_self(ll &x, ll y){ x = mn(x, y); }
void add(ll &x, ll y){ x += (y%MOD); x %= MOD; }
void mul(ll &x, ll y){ x%=MOD; x *= (y%MOD); x %= MOD; }

ll us(ll n, ll x, ll m){
    if(x == 0) return 1;
    ll a = us(n, x>>1, m);
    return (((a*a)%m)*(x&1?n:1))%m;
}

vvpll AdjList;
vll dep;
vector<set<pll>> s;
ll n, k, res = INF;

void dfs(ll u, ll par, ll cur){
    forn(sz(AdjList[u]), i){
        ll v = AdjList[u][i].st, w = AdjList[u][i].nd; 
        if(v == par) continue;

        dep[v] = dep[u]+1;
        dfs(v, u, cur + w);

        auto itr = s[v].lower_bound(mp(cur+k, -1));
        if(itr != s[v].end() and (*itr).st == cur+k){
            res = mn(res, (*itr).nd - dep[u]);
            //cout << "Node " << u << " nun altinda benden" << cur+k << " uzaklikta var.\n";
        }
        if(sz(s[v]) > sz(s[u])){ swap(s[v], s[u]); }

        for(itr = s[v].begin(); itr != s[v].end(); ++itr){
            pll p = *itr;
            auto it = s[u].lower_bound(mp(k+2*cur-p.st, -1));
            if(it != s[u].end() and (it->st) == k+2*cur-p.st){
                res = mn(res, (it->nd)+p.nd-2*dep[u]);
                //cout << "Ben " << u << "yum. Iki nodeum {" <<  itr->st << sp << itr->nd << "} {" << it->st << sp << it->nd << "}\n";
            }
        }
        for(auto itr = s[v].begin(); itr != s[v].end(); ++itr) s[u].insert(*itr);
    }
    auto itr = s[u].lower_bound(mp(cur+k, -1));
    if(itr != s[u].end() and (*itr).st == cur+k) res = mn(res, (*itr).nd);
    s[u].insert(mp(cur, dep[u]));
    return;
}

int best_path(int N, int K, int H[][2], int L[]){
    n = N, k = K;
    AdjList.resize(n);
    dep.resize(n);
    s.resize(n);
    forn(n-1, i){
        AdjList[H[i][0]].pb(mp(H[i][1], L[i]));
        AdjList[H[i][1]].pb(mp(H[i][0], L[i]));
    }
    dfs(0, -1, 0);
    return (res>=2e9?-1:res);
}

/*int main(int argc, char** argv){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    //freopen("race.gir", "r", stdin);
    //freopen("race.cik", "w", stdout);

    cin >> n >> k;
    AdjList.resize(n);
    dep.resize(n);
    s.resize(n);
    forn(n-1, i){
        ll u, v, w;
        cin >> u >> v >> w;
        AdjList[u].pb(mp(v, w));
        AdjList[v].pb(mp(u, w));
    }
    dfs(0, -1, 0);
    cout << ((res>=2e9)?-1:res) << endl;

    return 0;
}*/

//cikisir

# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 380 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 6 ms 376 KB Output is correct
8 Correct 5 ms 380 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 380 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 6 ms 376 KB Output is correct
8 Correct 5 ms 380 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 6 ms 632 KB Output is correct
22 Correct 6 ms 632 KB Output is correct
23 Correct 7 ms 760 KB Output is correct
24 Correct 7 ms 632 KB Output is correct
25 Correct 6 ms 760 KB Output is correct
26 Correct 6 ms 632 KB Output is correct
27 Correct 6 ms 504 KB Output is correct
28 Correct 6 ms 760 KB Output is correct
29 Correct 6 ms 760 KB Output is correct
30 Correct 6 ms 632 KB Output is correct
31 Correct 6 ms 632 KB Output is correct
32 Correct 7 ms 632 KB Output is correct
33 Correct 6 ms 760 KB Output is correct
34 Correct 6 ms 632 KB Output is correct
35 Correct 6 ms 504 KB Output is correct
36 Correct 6 ms 632 KB Output is correct
37 Correct 6 ms 504 KB Output is correct
38 Correct 6 ms 632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 380 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 6 ms 376 KB Output is correct
8 Correct 5 ms 380 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 166 ms 31992 KB Output is correct
20 Correct 157 ms 31864 KB Output is correct
21 Correct 160 ms 31480 KB Output is correct
22 Correct 174 ms 30712 KB Output is correct
23 Correct 203 ms 45536 KB Output is correct
24 Correct 165 ms 33936 KB Output is correct
25 Correct 155 ms 33656 KB Output is correct
26 Correct 102 ms 38940 KB Output is correct
27 Correct 264 ms 47864 KB Output is correct
28 Correct 334 ms 77920 KB Output is correct
29 Correct 332 ms 76024 KB Output is correct
30 Correct 298 ms 47992 KB Output is correct
31 Correct 267 ms 47736 KB Output is correct
32 Correct 344 ms 47864 KB Output is correct
33 Correct 245 ms 43388 KB Output is correct
34 Correct 381 ms 76564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 380 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 6 ms 376 KB Output is correct
8 Correct 5 ms 380 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 6 ms 632 KB Output is correct
22 Correct 6 ms 632 KB Output is correct
23 Correct 7 ms 760 KB Output is correct
24 Correct 7 ms 632 KB Output is correct
25 Correct 6 ms 760 KB Output is correct
26 Correct 6 ms 632 KB Output is correct
27 Correct 6 ms 504 KB Output is correct
28 Correct 6 ms 760 KB Output is correct
29 Correct 6 ms 760 KB Output is correct
30 Correct 6 ms 632 KB Output is correct
31 Correct 6 ms 632 KB Output is correct
32 Correct 7 ms 632 KB Output is correct
33 Correct 6 ms 760 KB Output is correct
34 Correct 6 ms 632 KB Output is correct
35 Correct 6 ms 504 KB Output is correct
36 Correct 6 ms 632 KB Output is correct
37 Correct 6 ms 504 KB Output is correct
38 Correct 6 ms 632 KB Output is correct
39 Correct 166 ms 31992 KB Output is correct
40 Correct 157 ms 31864 KB Output is correct
41 Correct 160 ms 31480 KB Output is correct
42 Correct 174 ms 30712 KB Output is correct
43 Correct 203 ms 45536 KB Output is correct
44 Correct 165 ms 33936 KB Output is correct
45 Correct 155 ms 33656 KB Output is correct
46 Correct 102 ms 38940 KB Output is correct
47 Correct 264 ms 47864 KB Output is correct
48 Correct 334 ms 77920 KB Output is correct
49 Correct 332 ms 76024 KB Output is correct
50 Correct 298 ms 47992 KB Output is correct
51 Correct 267 ms 47736 KB Output is correct
52 Correct 344 ms 47864 KB Output is correct
53 Correct 245 ms 43388 KB Output is correct
54 Correct 381 ms 76564 KB Output is correct
55 Correct 20 ms 4216 KB Output is correct
56 Correct 14 ms 2936 KB Output is correct
57 Correct 94 ms 27384 KB Output is correct
58 Correct 65 ms 21352 KB Output is correct
59 Correct 94 ms 38904 KB Output is correct
60 Correct 274 ms 76536 KB Output is correct
61 Correct 314 ms 53628 KB Output is correct
62 Correct 278 ms 48248 KB Output is correct
63 Correct 326 ms 47992 KB Output is correct
64 Correct 509 ms 104312 KB Output is correct
65 Correct 507 ms 97272 KB Output is correct
66 Correct 326 ms 72572 KB Output is correct
67 Correct 217 ms 43744 KB Output is correct
68 Correct 442 ms 64760 KB Output is correct
69 Correct 461 ms 70392 KB Output is correct
70 Correct 409 ms 61944 KB Output is correct