Submission #988879

# Submission time Handle Problem Language Result Execution time Memory
988879 2024-05-26T14:24:56 Z NoLove Race (IOI11_race) C++14
100 / 100
325 ms 102740 KB
/**
 *    author : Lăng Trọng Đạt
 *    created: 26-05-2024 
**/
#include <bits/stdc++.h>
using namespace std;
#ifndef LANG_DAT
#define db(...) ;
#endif // LANG_DAT
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define all(v) (v).begin(), (v).end()
using pii = pair<int, int>;
using vi = vector<int>;
#define FOR(i, a, b) for (int (i) = a; (i) <= (b); i++)
void mx(int& a, int b) { if (b > a) a = b; }
void mi(int& a, int b) { if (b < a) a = b; }
#define si(x) (int)(x.size())
const int INF = 1e18;
const int MOD = 1e9 + 7;

const int MAXN = 5e5 + 5;
int g[MAXN];
int n, ans = INF, k;
vector<pii> adj[MAXN];
map<int, int> md[MAXN]; // md[v][l] = độ sâu lớn nhất khi đi khoảng cách từ node đó đến root đúng = l

void dfs(int v, int prv, int len, int d) {
    md[v][len] = d;
    for (auto[u, l] : adj[v]) {
        if (u == prv) continue;
        dfs(u, v, len + l, d + 1);
        if (si(md[u]) > si(md[v])) swap(md[u], md[v]);
        // x + y - 2 * len = k
        // length = depth + depth_y - 2*d
        for (auto[x, depth] : md[u]) {
            if (md[v].count(k + 2*len - x)) {
                mi(ans, depth + md[v][k + 2*len - x] - 2*d);
            }
        }
        for (auto[x, depth] : md[u]) {
            if (md[v].count(x)) {
                mi(md[v][x], depth);
            } else {
                md[v][x] = depth;
            }
        }
    }
}
int best_path(int N, int K, int H[][2], int L[])
{
    k = K;
    FOR(i, 0, N - 2) {
        adj[H[i][0]].pb({H[i][1], L[i]});
        adj[H[i][1]].pb({H[i][0], L[i]});
    }
    dfs(1, -1, 0, 0);

    return (ans == INF ? -1 : ans);
}

Compilation message

race.cpp:21:17: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   21 | const int INF = 1e18;
      |                 ^~~~
race.cpp: In function 'void dfs(int, int, int, int)':
race.cpp:32:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   32 |     for (auto[u, l] : adj[v]) {
      |              ^
race.cpp:38:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   38 |         for (auto[x, depth] : md[u]) {
      |                  ^
race.cpp:43:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   43 |         for (auto[x, depth] : md[u]) {
      |                  ^
race.cpp: In function 'int best_path(int, int, int (*)[2], int*)':
race.cpp:17:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   17 | #define FOR(i, a, b) for (int (i) = a; (i) <= (b); i++)
      |                               ^
race.cpp:55:5: note: in expansion of macro 'FOR'
   55 |     FOR(i, 0, N - 2) {
      |     ^~~
# Verdict Execution time Memory Grader output
1 Correct 15 ms 35672 KB Output is correct
2 Correct 14 ms 35612 KB Output is correct
3 Correct 17 ms 35636 KB Output is correct
4 Correct 14 ms 35688 KB Output is correct
5 Correct 13 ms 35616 KB Output is correct
6 Correct 14 ms 35676 KB Output is correct
7 Correct 14 ms 35672 KB Output is correct
8 Correct 14 ms 35676 KB Output is correct
9 Correct 13 ms 35704 KB Output is correct
10 Correct 14 ms 35672 KB Output is correct
11 Correct 14 ms 35676 KB Output is correct
12 Correct 14 ms 35676 KB Output is correct
13 Correct 15 ms 35676 KB Output is correct
14 Correct 15 ms 35672 KB Output is correct
15 Correct 14 ms 35672 KB Output is correct
16 Correct 14 ms 35676 KB Output is correct
17 Correct 14 ms 35576 KB Output is correct
18 Correct 15 ms 35704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 35672 KB Output is correct
2 Correct 14 ms 35612 KB Output is correct
3 Correct 17 ms 35636 KB Output is correct
4 Correct 14 ms 35688 KB Output is correct
5 Correct 13 ms 35616 KB Output is correct
6 Correct 14 ms 35676 KB Output is correct
7 Correct 14 ms 35672 KB Output is correct
8 Correct 14 ms 35676 KB Output is correct
9 Correct 13 ms 35704 KB Output is correct
10 Correct 14 ms 35672 KB Output is correct
11 Correct 14 ms 35676 KB Output is correct
12 Correct 14 ms 35676 KB Output is correct
13 Correct 15 ms 35676 KB Output is correct
14 Correct 15 ms 35672 KB Output is correct
15 Correct 14 ms 35672 KB Output is correct
16 Correct 14 ms 35676 KB Output is correct
17 Correct 14 ms 35576 KB Output is correct
18 Correct 15 ms 35704 KB Output is correct
19 Correct 19 ms 35676 KB Output is correct
20 Correct 14 ms 35692 KB Output is correct
21 Correct 14 ms 35676 KB Output is correct
22 Correct 15 ms 35676 KB Output is correct
23 Correct 16 ms 35932 KB Output is correct
24 Correct 15 ms 35676 KB Output is correct
25 Correct 15 ms 35820 KB Output is correct
26 Correct 15 ms 35852 KB Output is correct
27 Correct 14 ms 35676 KB Output is correct
28 Correct 20 ms 35676 KB Output is correct
29 Correct 15 ms 35676 KB Output is correct
30 Correct 15 ms 35808 KB Output is correct
31 Correct 15 ms 35688 KB Output is correct
32 Correct 15 ms 35676 KB Output is correct
33 Correct 16 ms 35672 KB Output is correct
34 Correct 16 ms 35928 KB Output is correct
35 Correct 15 ms 35672 KB Output is correct
36 Correct 14 ms 35676 KB Output is correct
37 Correct 15 ms 35672 KB Output is correct
38 Correct 14 ms 35676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 35672 KB Output is correct
2 Correct 14 ms 35612 KB Output is correct
3 Correct 17 ms 35636 KB Output is correct
4 Correct 14 ms 35688 KB Output is correct
5 Correct 13 ms 35616 KB Output is correct
6 Correct 14 ms 35676 KB Output is correct
7 Correct 14 ms 35672 KB Output is correct
8 Correct 14 ms 35676 KB Output is correct
9 Correct 13 ms 35704 KB Output is correct
10 Correct 14 ms 35672 KB Output is correct
11 Correct 14 ms 35676 KB Output is correct
12 Correct 14 ms 35676 KB Output is correct
13 Correct 15 ms 35676 KB Output is correct
14 Correct 15 ms 35672 KB Output is correct
15 Correct 14 ms 35672 KB Output is correct
16 Correct 14 ms 35676 KB Output is correct
17 Correct 14 ms 35576 KB Output is correct
18 Correct 15 ms 35704 KB Output is correct
19 Correct 88 ms 52112 KB Output is correct
20 Correct 86 ms 53168 KB Output is correct
21 Correct 88 ms 52644 KB Output is correct
22 Correct 90 ms 53072 KB Output is correct
23 Correct 127 ms 62548 KB Output is correct
24 Correct 95 ms 55376 KB Output is correct
25 Correct 74 ms 60240 KB Output is correct
26 Correct 55 ms 61280 KB Output is correct
27 Correct 138 ms 61264 KB Output is correct
28 Correct 196 ms 94728 KB Output is correct
29 Correct 219 ms 87488 KB Output is correct
30 Correct 130 ms 62032 KB Output is correct
31 Correct 132 ms 62032 KB Output is correct
32 Correct 164 ms 61776 KB Output is correct
33 Correct 153 ms 65508 KB Output is correct
34 Correct 244 ms 90560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 35672 KB Output is correct
2 Correct 14 ms 35612 KB Output is correct
3 Correct 17 ms 35636 KB Output is correct
4 Correct 14 ms 35688 KB Output is correct
5 Correct 13 ms 35616 KB Output is correct
6 Correct 14 ms 35676 KB Output is correct
7 Correct 14 ms 35672 KB Output is correct
8 Correct 14 ms 35676 KB Output is correct
9 Correct 13 ms 35704 KB Output is correct
10 Correct 14 ms 35672 KB Output is correct
11 Correct 14 ms 35676 KB Output is correct
12 Correct 14 ms 35676 KB Output is correct
13 Correct 15 ms 35676 KB Output is correct
14 Correct 15 ms 35672 KB Output is correct
15 Correct 14 ms 35672 KB Output is correct
16 Correct 14 ms 35676 KB Output is correct
17 Correct 14 ms 35576 KB Output is correct
18 Correct 15 ms 35704 KB Output is correct
19 Correct 19 ms 35676 KB Output is correct
20 Correct 14 ms 35692 KB Output is correct
21 Correct 14 ms 35676 KB Output is correct
22 Correct 15 ms 35676 KB Output is correct
23 Correct 16 ms 35932 KB Output is correct
24 Correct 15 ms 35676 KB Output is correct
25 Correct 15 ms 35820 KB Output is correct
26 Correct 15 ms 35852 KB Output is correct
27 Correct 14 ms 35676 KB Output is correct
28 Correct 20 ms 35676 KB Output is correct
29 Correct 15 ms 35676 KB Output is correct
30 Correct 15 ms 35808 KB Output is correct
31 Correct 15 ms 35688 KB Output is correct
32 Correct 15 ms 35676 KB Output is correct
33 Correct 16 ms 35672 KB Output is correct
34 Correct 16 ms 35928 KB Output is correct
35 Correct 15 ms 35672 KB Output is correct
36 Correct 14 ms 35676 KB Output is correct
37 Correct 15 ms 35672 KB Output is correct
38 Correct 14 ms 35676 KB Output is correct
39 Correct 88 ms 52112 KB Output is correct
40 Correct 86 ms 53168 KB Output is correct
41 Correct 88 ms 52644 KB Output is correct
42 Correct 90 ms 53072 KB Output is correct
43 Correct 127 ms 62548 KB Output is correct
44 Correct 95 ms 55376 KB Output is correct
45 Correct 74 ms 60240 KB Output is correct
46 Correct 55 ms 61280 KB Output is correct
47 Correct 138 ms 61264 KB Output is correct
48 Correct 196 ms 94728 KB Output is correct
49 Correct 219 ms 87488 KB Output is correct
50 Correct 130 ms 62032 KB Output is correct
51 Correct 132 ms 62032 KB Output is correct
52 Correct 164 ms 61776 KB Output is correct
53 Correct 153 ms 65508 KB Output is correct
54 Correct 244 ms 90560 KB Output is correct
55 Correct 24 ms 38224 KB Output is correct
56 Correct 25 ms 36952 KB Output is correct
57 Correct 53 ms 50256 KB Output is correct
58 Correct 43 ms 46444 KB Output is correct
59 Correct 76 ms 65876 KB Output is correct
60 Correct 187 ms 84820 KB Output is correct
61 Correct 162 ms 63836 KB Output is correct
62 Correct 123 ms 61936 KB Output is correct
63 Correct 151 ms 61776 KB Output is correct
64 Correct 325 ms 102740 KB Output is correct
65 Correct 311 ms 102484 KB Output is correct
66 Correct 192 ms 90960 KB Output is correct
67 Correct 108 ms 58812 KB Output is correct
68 Correct 244 ms 74488 KB Output is correct
69 Correct 262 ms 76112 KB Output is correct
70 Correct 218 ms 73108 KB Output is correct