답안 #667077

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
667077 2022-11-30T10:47:48 Z Bogdan1110 경주 (Race) (IOI11_race) C++14
100 / 100
400 ms 122560 KB
#include <bits/stdc++.h>
#include "race.h"
#define FAST {ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
#define FILES {freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);}
#define ll long long
#define ull unsigned long long
#define pqueue priority_queue
#define pb push_back
#define fi first
#define se second
#define ld long double
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(a) (a).begin(), (a).end()
#define mp make_pair 
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
 
#define ordered_set tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key -> # less than k
// find_by_order -> k-th element
// pq max element
 
const double eps = 0.00000001;
const int NMAX = 2000010;
const ll inf = LLONG_MAX/3;
const ll modi = 998244353;
 
int K;
int visited[NMAX];
vector<pii>al[NMAX];
ll res = INT_MAX;
map<ll,ll> dfs(ll node, ll dep, ll kol) {
    map<ll,ll>r;
    r[kol] = dep;
    if ( visited[node] ) {
        return r;
    }
    visited[node] = 1;
    for (auto u : al[node]) {
        if ( visited[u.fi] ) continue;
        map<ll,ll>t = dfs(u.fi, dep+1, kol + u.se);
        if ( t.size() > r.size() ) swap(t,r);
 
        for (auto k:t) {
            int temp = K-k.fi+2*kol;
            if ( r.find(temp) != r.end() ) {
                res = min(res, k.se + r[temp] - 2*dep);
            }
        }
        for (auto k:t) {
            if ( r.find(k.fi) != r.end() ) {
                r[k.fi] = min(r[k.fi], k.se);
            }
            else {
                r[k.fi] = k.se;
            }
        }
    }
    //cout << node << ' ' << dep << ' '<< kol << endl;
    return r;
}
 
int best_path(int n, int k, int h[][2], int l[])
{
    K = k;
    for (int i = 0 ; i < n-1 ; i++ ) {
        al[h[i][0]].pb({h[i][1],l[i]});
        al[h[i][1]].pb({h[i][0],l[i]});
    }
 
    for (int i = 0; i < n ; i++ ) {
        if ( al[i].size() == 1 ) {
            dfs(i,0,0);
            break;
        }
    }
    if ( res == INT_MAX) return -1;
    return res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 47316 KB Output is correct
2 Correct 21 ms 47316 KB Output is correct
3 Correct 24 ms 47232 KB Output is correct
4 Correct 21 ms 47236 KB Output is correct
5 Correct 22 ms 47320 KB Output is correct
6 Correct 23 ms 47196 KB Output is correct
7 Correct 22 ms 47208 KB Output is correct
8 Correct 26 ms 47316 KB Output is correct
9 Correct 22 ms 47288 KB Output is correct
10 Correct 22 ms 47316 KB Output is correct
11 Correct 26 ms 47204 KB Output is correct
12 Correct 22 ms 47192 KB Output is correct
13 Correct 23 ms 47260 KB Output is correct
14 Correct 22 ms 47312 KB Output is correct
15 Correct 23 ms 47316 KB Output is correct
16 Correct 23 ms 47316 KB Output is correct
17 Correct 22 ms 47316 KB Output is correct
18 Correct 22 ms 47320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 47316 KB Output is correct
2 Correct 21 ms 47316 KB Output is correct
3 Correct 24 ms 47232 KB Output is correct
4 Correct 21 ms 47236 KB Output is correct
5 Correct 22 ms 47320 KB Output is correct
6 Correct 23 ms 47196 KB Output is correct
7 Correct 22 ms 47208 KB Output is correct
8 Correct 26 ms 47316 KB Output is correct
9 Correct 22 ms 47288 KB Output is correct
10 Correct 22 ms 47316 KB Output is correct
11 Correct 26 ms 47204 KB Output is correct
12 Correct 22 ms 47192 KB Output is correct
13 Correct 23 ms 47260 KB Output is correct
14 Correct 22 ms 47312 KB Output is correct
15 Correct 23 ms 47316 KB Output is correct
16 Correct 23 ms 47316 KB Output is correct
17 Correct 22 ms 47316 KB Output is correct
18 Correct 22 ms 47320 KB Output is correct
19 Correct 24 ms 47232 KB Output is correct
20 Correct 22 ms 47288 KB Output is correct
21 Correct 22 ms 47312 KB Output is correct
22 Correct 23 ms 47316 KB Output is correct
23 Correct 23 ms 47344 KB Output is correct
24 Correct 24 ms 47288 KB Output is correct
25 Correct 24 ms 47304 KB Output is correct
26 Correct 23 ms 47424 KB Output is correct
27 Correct 24 ms 47340 KB Output is correct
28 Correct 23 ms 47384 KB Output is correct
29 Correct 24 ms 47552 KB Output is correct
30 Correct 23 ms 47400 KB Output is correct
31 Correct 27 ms 47368 KB Output is correct
32 Correct 24 ms 47296 KB Output is correct
33 Correct 24 ms 47404 KB Output is correct
34 Correct 23 ms 47460 KB Output is correct
35 Correct 22 ms 47432 KB Output is correct
36 Correct 26 ms 47404 KB Output is correct
37 Correct 29 ms 47408 KB Output is correct
38 Correct 24 ms 47340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 47316 KB Output is correct
2 Correct 21 ms 47316 KB Output is correct
3 Correct 24 ms 47232 KB Output is correct
4 Correct 21 ms 47236 KB Output is correct
5 Correct 22 ms 47320 KB Output is correct
6 Correct 23 ms 47196 KB Output is correct
7 Correct 22 ms 47208 KB Output is correct
8 Correct 26 ms 47316 KB Output is correct
9 Correct 22 ms 47288 KB Output is correct
10 Correct 22 ms 47316 KB Output is correct
11 Correct 26 ms 47204 KB Output is correct
12 Correct 22 ms 47192 KB Output is correct
13 Correct 23 ms 47260 KB Output is correct
14 Correct 22 ms 47312 KB Output is correct
15 Correct 23 ms 47316 KB Output is correct
16 Correct 23 ms 47316 KB Output is correct
17 Correct 22 ms 47316 KB Output is correct
18 Correct 22 ms 47320 KB Output is correct
19 Correct 113 ms 52588 KB Output is correct
20 Correct 102 ms 53948 KB Output is correct
21 Correct 104 ms 53944 KB Output is correct
22 Correct 107 ms 53944 KB Output is correct
23 Correct 139 ms 54464 KB Output is correct
24 Correct 108 ms 54140 KB Output is correct
25 Correct 96 ms 84520 KB Output is correct
26 Correct 94 ms 84528 KB Output is correct
27 Correct 187 ms 61148 KB Output is correct
28 Correct 288 ms 122352 KB Output is correct
29 Correct 283 ms 122436 KB Output is correct
30 Correct 178 ms 61184 KB Output is correct
31 Correct 194 ms 61148 KB Output is correct
32 Correct 199 ms 61420 KB Output is correct
33 Correct 191 ms 60792 KB Output is correct
34 Correct 303 ms 75628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 47316 KB Output is correct
2 Correct 21 ms 47316 KB Output is correct
3 Correct 24 ms 47232 KB Output is correct
4 Correct 21 ms 47236 KB Output is correct
5 Correct 22 ms 47320 KB Output is correct
6 Correct 23 ms 47196 KB Output is correct
7 Correct 22 ms 47208 KB Output is correct
8 Correct 26 ms 47316 KB Output is correct
9 Correct 22 ms 47288 KB Output is correct
10 Correct 22 ms 47316 KB Output is correct
11 Correct 26 ms 47204 KB Output is correct
12 Correct 22 ms 47192 KB Output is correct
13 Correct 23 ms 47260 KB Output is correct
14 Correct 22 ms 47312 KB Output is correct
15 Correct 23 ms 47316 KB Output is correct
16 Correct 23 ms 47316 KB Output is correct
17 Correct 22 ms 47316 KB Output is correct
18 Correct 22 ms 47320 KB Output is correct
19 Correct 24 ms 47232 KB Output is correct
20 Correct 22 ms 47288 KB Output is correct
21 Correct 22 ms 47312 KB Output is correct
22 Correct 23 ms 47316 KB Output is correct
23 Correct 23 ms 47344 KB Output is correct
24 Correct 24 ms 47288 KB Output is correct
25 Correct 24 ms 47304 KB Output is correct
26 Correct 23 ms 47424 KB Output is correct
27 Correct 24 ms 47340 KB Output is correct
28 Correct 23 ms 47384 KB Output is correct
29 Correct 24 ms 47552 KB Output is correct
30 Correct 23 ms 47400 KB Output is correct
31 Correct 27 ms 47368 KB Output is correct
32 Correct 24 ms 47296 KB Output is correct
33 Correct 24 ms 47404 KB Output is correct
34 Correct 23 ms 47460 KB Output is correct
35 Correct 22 ms 47432 KB Output is correct
36 Correct 26 ms 47404 KB Output is correct
37 Correct 29 ms 47408 KB Output is correct
38 Correct 24 ms 47340 KB Output is correct
39 Correct 113 ms 52588 KB Output is correct
40 Correct 102 ms 53948 KB Output is correct
41 Correct 104 ms 53944 KB Output is correct
42 Correct 107 ms 53944 KB Output is correct
43 Correct 139 ms 54464 KB Output is correct
44 Correct 108 ms 54140 KB Output is correct
45 Correct 96 ms 84520 KB Output is correct
46 Correct 94 ms 84528 KB Output is correct
47 Correct 187 ms 61148 KB Output is correct
48 Correct 288 ms 122352 KB Output is correct
49 Correct 283 ms 122436 KB Output is correct
50 Correct 178 ms 61184 KB Output is correct
51 Correct 194 ms 61148 KB Output is correct
52 Correct 199 ms 61420 KB Output is correct
53 Correct 191 ms 60792 KB Output is correct
54 Correct 303 ms 75628 KB Output is correct
55 Correct 34 ms 48332 KB Output is correct
56 Correct 31 ms 47820 KB Output is correct
57 Correct 72 ms 54084 KB Output is correct
58 Correct 62 ms 53772 KB Output is correct
59 Correct 102 ms 84544 KB Output is correct
60 Correct 285 ms 122276 KB Output is correct
61 Correct 202 ms 63068 KB Output is correct
62 Correct 171 ms 61288 KB Output is correct
63 Correct 186 ms 61412 KB Output is correct
64 Correct 400 ms 70324 KB Output is correct
65 Correct 380 ms 74316 KB Output is correct
66 Correct 285 ms 122560 KB Output is correct
67 Correct 142 ms 61644 KB Output is correct
68 Correct 321 ms 72424 KB Output is correct
69 Correct 320 ms 77012 KB Output is correct
70 Correct 263 ms 71572 KB Output is correct