답안 #426057

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
426057 2021-06-13T13:24:16 Z someone 경주 (Race) (IOI11_race) C++14
100 / 100
942 ms 59328 KB
#include "race.h"
#include <bits/stdc++.h>
using namespace std;

const int N = 2e5 + 10, K = 1e6 + 10, INF = 1e9;

bool ch[K];
vector<int> adj[N], len[N], upd;
int h[N], longueur, mini = INF, minAut[K];

void getMin(int i, int pre, int dist, int nbAut) {
    if(h[i] != -1 || dist > longueur)
        return;
    mini = min(mini, nbAut + minAut[longueur - dist]);
    nbAut++;
    int t = adj[i].size();
    for(int j = 0; j < t; j++)
        if(adj[i][j] != pre)
            getMin(adj[i][j], i, dist + len[i][j], nbAut);
}

void update(int i, int pre, int dist, int nbAut) {
    if(h[i] != -1 || dist > longueur)
        return;
    if(!ch[dist]) {
        ch[dist] = true;
        upd.push_back(dist);
    }
    minAut[dist] = min(minAut[dist], nbAut);
    nbAut++;
    int t = adj[i].size();
    for(int j = 0; j < t; j++)
        if(adj[i][j] != pre)
            update(adj[i][j], i, dist + len[i][j], nbAut);
}

int centroid(int i, int pre, int sz, int id) {
    if(h[i] != -1)
        return 0;
    //cout << "CALL " << i << ' ' << sz << ' ' << id << '\n';
    int t = adj[i].size(), s[t], sum = 1, v = -1;
    for(int j = 0; j < t; j++)
        if(adj[i][j] == pre) {
            v = j;
        } else {
            s[j] = centroid(adj[i][j], i, sz, id);
            sum += s[j];
        }
    if(v != -1)
        s[v] = sz - sum;
    int maxi = 0;
    for(int j = 0; j < t; j++)
        maxi = max(maxi, s[j]);
    //cout << "TEST " << i << ' ' << h[i] << ' ' << maxi << ' ' << (sz+1)/2 << ' ' << sz << '\n';
    if(h[i] == -1 && maxi <= sz/2) {
        h[i] = id;
        minAut[0] = 0;
        upd.push_back(0);
        for(int j = 0; j < t; j++) {
            getMin(adj[i][j], i, len[i][j], 1);
            update(adj[i][j], i, len[i][j], 1);
        }
        for(int j : upd) {
            ch[j] = false;
            minAut[j] = INF;
        }
        upd.clear();
        //cout << i << ' ' << h[i] << ' ' << t << '\n';
        id++;
        /*for(int j = 0; j < t; j++)
            cout << ' ' << adj[i][j] << ' ' << s[j] << '\n';*/
        for(int j = 0; j < t; j++)
            centroid(adj[i][j], i, s[j], id);
    }
    return sum;
}

int best_path(int n, int k, int H[][2], int L[]) {
    longueur = k;
    for(int i = 0; i < K; i++)
        minAut[i] = INF;
    for(int i = 0; i < n; i++)
        h[i] = -1;
    for(int i = 0; i < n-1; i++) {
        len[H[i][0]].push_back(L[i]);
        len[H[i][1]].push_back(L[i]);
        adj[H[i][0]].push_back(H[i][1]);
        adj[H[i][1]].push_back(H[i][0]);
    }
    centroid(0, -1, n, 0);
    if(mini == INF)
        return -1;
    return mini;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 13644 KB Output is correct
2 Correct 10 ms 13540 KB Output is correct
3 Correct 11 ms 13644 KB Output is correct
4 Correct 10 ms 13644 KB Output is correct
5 Correct 11 ms 13644 KB Output is correct
6 Correct 11 ms 13644 KB Output is correct
7 Correct 10 ms 13644 KB Output is correct
8 Correct 9 ms 13592 KB Output is correct
9 Correct 10 ms 13644 KB Output is correct
10 Correct 11 ms 13644 KB Output is correct
11 Correct 11 ms 13536 KB Output is correct
12 Correct 10 ms 13644 KB Output is correct
13 Correct 10 ms 13644 KB Output is correct
14 Correct 9 ms 13644 KB Output is correct
15 Correct 10 ms 13644 KB Output is correct
16 Correct 12 ms 13600 KB Output is correct
17 Correct 12 ms 13608 KB Output is correct
18 Correct 11 ms 13648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 13644 KB Output is correct
2 Correct 10 ms 13540 KB Output is correct
3 Correct 11 ms 13644 KB Output is correct
4 Correct 10 ms 13644 KB Output is correct
5 Correct 11 ms 13644 KB Output is correct
6 Correct 11 ms 13644 KB Output is correct
7 Correct 10 ms 13644 KB Output is correct
8 Correct 9 ms 13592 KB Output is correct
9 Correct 10 ms 13644 KB Output is correct
10 Correct 11 ms 13644 KB Output is correct
11 Correct 11 ms 13536 KB Output is correct
12 Correct 10 ms 13644 KB Output is correct
13 Correct 10 ms 13644 KB Output is correct
14 Correct 9 ms 13644 KB Output is correct
15 Correct 10 ms 13644 KB Output is correct
16 Correct 12 ms 13600 KB Output is correct
17 Correct 12 ms 13608 KB Output is correct
18 Correct 11 ms 13648 KB Output is correct
19 Correct 11 ms 13516 KB Output is correct
20 Correct 9 ms 13516 KB Output is correct
21 Correct 11 ms 13644 KB Output is correct
22 Correct 10 ms 14444 KB Output is correct
23 Correct 11 ms 14412 KB Output is correct
24 Correct 11 ms 14564 KB Output is correct
25 Correct 12 ms 14148 KB Output is correct
26 Correct 11 ms 13968 KB Output is correct
27 Correct 10 ms 13608 KB Output is correct
28 Correct 11 ms 13900 KB Output is correct
29 Correct 13 ms 14028 KB Output is correct
30 Correct 12 ms 14028 KB Output is correct
31 Correct 13 ms 14196 KB Output is correct
32 Correct 12 ms 14192 KB Output is correct
33 Correct 12 ms 14448 KB Output is correct
34 Correct 12 ms 14284 KB Output is correct
35 Correct 11 ms 14548 KB Output is correct
36 Correct 12 ms 14668 KB Output is correct
37 Correct 12 ms 14412 KB Output is correct
38 Correct 11 ms 14028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 13644 KB Output is correct
2 Correct 10 ms 13540 KB Output is correct
3 Correct 11 ms 13644 KB Output is correct
4 Correct 10 ms 13644 KB Output is correct
5 Correct 11 ms 13644 KB Output is correct
6 Correct 11 ms 13644 KB Output is correct
7 Correct 10 ms 13644 KB Output is correct
8 Correct 9 ms 13592 KB Output is correct
9 Correct 10 ms 13644 KB Output is correct
10 Correct 11 ms 13644 KB Output is correct
11 Correct 11 ms 13536 KB Output is correct
12 Correct 10 ms 13644 KB Output is correct
13 Correct 10 ms 13644 KB Output is correct
14 Correct 9 ms 13644 KB Output is correct
15 Correct 10 ms 13644 KB Output is correct
16 Correct 12 ms 13600 KB Output is correct
17 Correct 12 ms 13608 KB Output is correct
18 Correct 11 ms 13648 KB Output is correct
19 Correct 243 ms 22192 KB Output is correct
20 Correct 247 ms 22980 KB Output is correct
21 Correct 291 ms 22800 KB Output is correct
22 Correct 350 ms 23032 KB Output is correct
23 Correct 196 ms 23000 KB Output is correct
24 Correct 143 ms 23236 KB Output is correct
25 Correct 210 ms 30192 KB Output is correct
26 Correct 138 ms 36840 KB Output is correct
27 Correct 417 ms 32456 KB Output is correct
28 Correct 569 ms 59072 KB Output is correct
29 Correct 501 ms 57296 KB Output is correct
30 Correct 417 ms 32360 KB Output is correct
31 Correct 436 ms 32452 KB Output is correct
32 Correct 441 ms 32324 KB Output is correct
33 Correct 394 ms 31268 KB Output is correct
34 Correct 351 ms 31132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 13644 KB Output is correct
2 Correct 10 ms 13540 KB Output is correct
3 Correct 11 ms 13644 KB Output is correct
4 Correct 10 ms 13644 KB Output is correct
5 Correct 11 ms 13644 KB Output is correct
6 Correct 11 ms 13644 KB Output is correct
7 Correct 10 ms 13644 KB Output is correct
8 Correct 9 ms 13592 KB Output is correct
9 Correct 10 ms 13644 KB Output is correct
10 Correct 11 ms 13644 KB Output is correct
11 Correct 11 ms 13536 KB Output is correct
12 Correct 10 ms 13644 KB Output is correct
13 Correct 10 ms 13644 KB Output is correct
14 Correct 9 ms 13644 KB Output is correct
15 Correct 10 ms 13644 KB Output is correct
16 Correct 12 ms 13600 KB Output is correct
17 Correct 12 ms 13608 KB Output is correct
18 Correct 11 ms 13648 KB Output is correct
19 Correct 11 ms 13516 KB Output is correct
20 Correct 9 ms 13516 KB Output is correct
21 Correct 11 ms 13644 KB Output is correct
22 Correct 10 ms 14444 KB Output is correct
23 Correct 11 ms 14412 KB Output is correct
24 Correct 11 ms 14564 KB Output is correct
25 Correct 12 ms 14148 KB Output is correct
26 Correct 11 ms 13968 KB Output is correct
27 Correct 10 ms 13608 KB Output is correct
28 Correct 11 ms 13900 KB Output is correct
29 Correct 13 ms 14028 KB Output is correct
30 Correct 12 ms 14028 KB Output is correct
31 Correct 13 ms 14196 KB Output is correct
32 Correct 12 ms 14192 KB Output is correct
33 Correct 12 ms 14448 KB Output is correct
34 Correct 12 ms 14284 KB Output is correct
35 Correct 11 ms 14548 KB Output is correct
36 Correct 12 ms 14668 KB Output is correct
37 Correct 12 ms 14412 KB Output is correct
38 Correct 11 ms 14028 KB Output is correct
39 Correct 243 ms 22192 KB Output is correct
40 Correct 247 ms 22980 KB Output is correct
41 Correct 291 ms 22800 KB Output is correct
42 Correct 350 ms 23032 KB Output is correct
43 Correct 196 ms 23000 KB Output is correct
44 Correct 143 ms 23236 KB Output is correct
45 Correct 210 ms 30192 KB Output is correct
46 Correct 138 ms 36840 KB Output is correct
47 Correct 417 ms 32456 KB Output is correct
48 Correct 569 ms 59072 KB Output is correct
49 Correct 501 ms 57296 KB Output is correct
50 Correct 417 ms 32360 KB Output is correct
51 Correct 436 ms 32452 KB Output is correct
52 Correct 441 ms 32324 KB Output is correct
53 Correct 394 ms 31268 KB Output is correct
54 Correct 351 ms 31132 KB Output is correct
55 Correct 22 ms 14540 KB Output is correct
56 Correct 22 ms 14540 KB Output is correct
57 Correct 126 ms 22776 KB Output is correct
58 Correct 57 ms 23644 KB Output is correct
59 Correct 175 ms 37604 KB Output is correct
60 Correct 885 ms 59328 KB Output is correct
61 Correct 379 ms 32372 KB Output is correct
62 Correct 413 ms 32196 KB Output is correct
63 Correct 532 ms 32196 KB Output is correct
64 Correct 942 ms 32060 KB Output is correct
65 Correct 583 ms 31308 KB Output is correct
66 Correct 707 ms 53152 KB Output is correct
67 Correct 300 ms 33196 KB Output is correct
68 Correct 634 ms 33460 KB Output is correct
69 Correct 565 ms 33824 KB Output is correct
70 Correct 575 ms 32832 KB Output is correct