답안 #888439

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
888439 2023-12-17T12:02:54 Z TitanSlayer 경주 (Race) (IOI11_race) C++14
100 / 100
393 ms 109652 KB
#include "bits/stdc++.h"
#include "race.h"
using namespace std;
#define ll long long
#define ld long double
#define vv vector
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define mod 1000000007

typedef pair<ll, ll> pll;
typedef vv<ll> vll;
typedef vv<ld> vld;
typedef vv<pll> vpll;
typedef set<ll>::iterator sitr;

#define fastio                    \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);
///////////////////////////////////

ll n, k, ans = 1e9;
vector<map<ll, ll>> m(200005);
vv<vpll> v(200005);
pll offset[200005];

void dfs(ll node, ll par)
{
    // cout << node << " " << par << endl;
    m[node][0] = 0;
    offset[node] = {0, 0};
    for (auto child : v[node])
    {
        if (child.F == par)
            continue;
        dfs(child.F, node);

        offset[child.F].F += child.S;
        offset[child.F].S += 1;
        if (m[child.F].size() > m[node].size())
        {
            swap(m[child.F], m[node]);
            swap(offset[child.F], offset[node]);
        }

        for (auto itr_child : m[child.F])
        {
            ll dist = itr_child.F + offset[child.F].F;
            ll cnt = itr_child.S + offset[child.F].S;
            auto itr_par = m[node].find(k - dist - offset[node].F);
            if (itr_par != m[node].end())
                ans = min(ans, cnt + itr_par->second + offset[node].S);
        }

        for (auto itr_child : m[child.F])
        {
            ll dist = itr_child.F + offset[child.F].F - offset[node].F;
            ll cnt = itr_child.S + offset[child.F].S - offset[node].S;

            auto itr_par = m[node].find(dist);
            if (itr_par != m[node].end())
                m[node][dist] = min(cnt, m[node][dist]);
            else
                m[node][dist] = cnt;
        }
    }
}

int best_path(int N, int K, int H[][2], int L[])
{
    ll i, j, a, b, c;
    n = N;
    k = K;

    for (i = 0; i < n - 1; i++)
    {
        a = H[i][0];
        b = H[i][1];
        c = L[i];
        v[a].pb({b, c});
        v[b].pb({a, c});
    }

    dfs(0, -1);

    if (ans == 1e9)
        ans = -1;
    return (int)ans;
}

Compilation message

race.cpp: In function 'int best_path(int, int, int (*)[2], int*)':
race.cpp:73:11: warning: unused variable 'j' [-Wunused-variable]
   73 |     ll i, j, a, b, c;
      |           ^
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 18524 KB Output is correct
2 Correct 5 ms 18524 KB Output is correct
3 Correct 4 ms 18524 KB Output is correct
4 Correct 5 ms 18524 KB Output is correct
5 Correct 4 ms 18524 KB Output is correct
6 Correct 5 ms 18524 KB Output is correct
7 Correct 5 ms 18648 KB Output is correct
8 Correct 5 ms 18524 KB Output is correct
9 Correct 5 ms 18520 KB Output is correct
10 Correct 5 ms 18524 KB Output is correct
11 Correct 5 ms 18524 KB Output is correct
12 Correct 4 ms 18524 KB Output is correct
13 Correct 4 ms 18524 KB Output is correct
14 Correct 4 ms 18520 KB Output is correct
15 Correct 5 ms 18608 KB Output is correct
16 Correct 5 ms 18524 KB Output is correct
17 Correct 4 ms 18524 KB Output is correct
18 Correct 5 ms 18524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 18524 KB Output is correct
2 Correct 5 ms 18524 KB Output is correct
3 Correct 4 ms 18524 KB Output is correct
4 Correct 5 ms 18524 KB Output is correct
5 Correct 4 ms 18524 KB Output is correct
6 Correct 5 ms 18524 KB Output is correct
7 Correct 5 ms 18648 KB Output is correct
8 Correct 5 ms 18524 KB Output is correct
9 Correct 5 ms 18520 KB Output is correct
10 Correct 5 ms 18524 KB Output is correct
11 Correct 5 ms 18524 KB Output is correct
12 Correct 4 ms 18524 KB Output is correct
13 Correct 4 ms 18524 KB Output is correct
14 Correct 4 ms 18520 KB Output is correct
15 Correct 5 ms 18608 KB Output is correct
16 Correct 5 ms 18524 KB Output is correct
17 Correct 4 ms 18524 KB Output is correct
18 Correct 5 ms 18524 KB Output is correct
19 Correct 5 ms 18520 KB Output is correct
20 Correct 7 ms 18524 KB Output is correct
21 Correct 6 ms 18780 KB Output is correct
22 Correct 6 ms 18780 KB Output is correct
23 Correct 6 ms 18892 KB Output is correct
24 Correct 5 ms 18780 KB Output is correct
25 Correct 6 ms 18780 KB Output is correct
26 Correct 6 ms 18776 KB Output is correct
27 Correct 5 ms 18780 KB Output is correct
28 Correct 7 ms 18780 KB Output is correct
29 Correct 6 ms 18780 KB Output is correct
30 Correct 6 ms 18780 KB Output is correct
31 Correct 6 ms 18784 KB Output is correct
32 Correct 5 ms 18760 KB Output is correct
33 Correct 5 ms 18780 KB Output is correct
34 Correct 6 ms 19032 KB Output is correct
35 Correct 5 ms 18780 KB Output is correct
36 Correct 5 ms 18780 KB Output is correct
37 Correct 5 ms 18776 KB Output is correct
38 Correct 5 ms 18780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 18524 KB Output is correct
2 Correct 5 ms 18524 KB Output is correct
3 Correct 4 ms 18524 KB Output is correct
4 Correct 5 ms 18524 KB Output is correct
5 Correct 4 ms 18524 KB Output is correct
6 Correct 5 ms 18524 KB Output is correct
7 Correct 5 ms 18648 KB Output is correct
8 Correct 5 ms 18524 KB Output is correct
9 Correct 5 ms 18520 KB Output is correct
10 Correct 5 ms 18524 KB Output is correct
11 Correct 5 ms 18524 KB Output is correct
12 Correct 4 ms 18524 KB Output is correct
13 Correct 4 ms 18524 KB Output is correct
14 Correct 4 ms 18520 KB Output is correct
15 Correct 5 ms 18608 KB Output is correct
16 Correct 5 ms 18524 KB Output is correct
17 Correct 4 ms 18524 KB Output is correct
18 Correct 5 ms 18524 KB Output is correct
19 Correct 116 ms 43640 KB Output is correct
20 Correct 103 ms 43588 KB Output is correct
21 Correct 96 ms 43224 KB Output is correct
22 Correct 109 ms 42880 KB Output is correct
23 Correct 141 ms 55720 KB Output is correct
24 Correct 106 ms 45652 KB Output is correct
25 Correct 88 ms 43604 KB Output is correct
26 Correct 51 ms 51036 KB Output is correct
27 Correct 150 ms 53356 KB Output is correct
28 Correct 239 ms 92244 KB Output is correct
29 Correct 271 ms 90448 KB Output is correct
30 Correct 150 ms 53120 KB Output is correct
31 Correct 139 ms 53192 KB Output is correct
32 Correct 214 ms 53308 KB Output is correct
33 Correct 194 ms 58144 KB Output is correct
34 Correct 288 ms 90192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 18524 KB Output is correct
2 Correct 5 ms 18524 KB Output is correct
3 Correct 4 ms 18524 KB Output is correct
4 Correct 5 ms 18524 KB Output is correct
5 Correct 4 ms 18524 KB Output is correct
6 Correct 5 ms 18524 KB Output is correct
7 Correct 5 ms 18648 KB Output is correct
8 Correct 5 ms 18524 KB Output is correct
9 Correct 5 ms 18520 KB Output is correct
10 Correct 5 ms 18524 KB Output is correct
11 Correct 5 ms 18524 KB Output is correct
12 Correct 4 ms 18524 KB Output is correct
13 Correct 4 ms 18524 KB Output is correct
14 Correct 4 ms 18520 KB Output is correct
15 Correct 5 ms 18608 KB Output is correct
16 Correct 5 ms 18524 KB Output is correct
17 Correct 4 ms 18524 KB Output is correct
18 Correct 5 ms 18524 KB Output is correct
19 Correct 5 ms 18520 KB Output is correct
20 Correct 7 ms 18524 KB Output is correct
21 Correct 6 ms 18780 KB Output is correct
22 Correct 6 ms 18780 KB Output is correct
23 Correct 6 ms 18892 KB Output is correct
24 Correct 5 ms 18780 KB Output is correct
25 Correct 6 ms 18780 KB Output is correct
26 Correct 6 ms 18776 KB Output is correct
27 Correct 5 ms 18780 KB Output is correct
28 Correct 7 ms 18780 KB Output is correct
29 Correct 6 ms 18780 KB Output is correct
30 Correct 6 ms 18780 KB Output is correct
31 Correct 6 ms 18784 KB Output is correct
32 Correct 5 ms 18760 KB Output is correct
33 Correct 5 ms 18780 KB Output is correct
34 Correct 6 ms 19032 KB Output is correct
35 Correct 5 ms 18780 KB Output is correct
36 Correct 5 ms 18780 KB Output is correct
37 Correct 5 ms 18776 KB Output is correct
38 Correct 5 ms 18780 KB Output is correct
39 Correct 116 ms 43640 KB Output is correct
40 Correct 103 ms 43588 KB Output is correct
41 Correct 96 ms 43224 KB Output is correct
42 Correct 109 ms 42880 KB Output is correct
43 Correct 141 ms 55720 KB Output is correct
44 Correct 106 ms 45652 KB Output is correct
45 Correct 88 ms 43604 KB Output is correct
46 Correct 51 ms 51036 KB Output is correct
47 Correct 150 ms 53356 KB Output is correct
48 Correct 239 ms 92244 KB Output is correct
49 Correct 271 ms 90448 KB Output is correct
50 Correct 150 ms 53120 KB Output is correct
51 Correct 139 ms 53192 KB Output is correct
52 Correct 214 ms 53308 KB Output is correct
53 Correct 194 ms 58144 KB Output is correct
54 Correct 288 ms 90192 KB Output is correct
55 Correct 15 ms 21596 KB Output is correct
56 Correct 11 ms 20472 KB Output is correct
57 Correct 59 ms 41048 KB Output is correct
58 Correct 42 ms 34496 KB Output is correct
59 Correct 91 ms 58192 KB Output is correct
60 Correct 236 ms 92952 KB Output is correct
61 Correct 211 ms 58448 KB Output is correct
62 Correct 138 ms 54900 KB Output is correct
63 Correct 205 ms 55024 KB Output is correct
64 Correct 377 ms 109652 KB Output is correct
65 Correct 393 ms 107604 KB Output is correct
66 Correct 253 ms 88700 KB Output is correct
67 Correct 140 ms 47840 KB Output is correct
68 Correct 276 ms 71024 KB Output is correct
69 Correct 304 ms 75692 KB Output is correct
70 Correct 249 ms 68928 KB Output is correct