Submission #885888

# Submission time Handle Problem Language Result Execution time Memory
885888 2023-12-11T00:54:22 Z bobbilyking Race (IOI11_race) C++17
43 / 100
206 ms 101516 KB
#include "race.h"

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pl = pair<ll, ll>;
#define NN 200010
#define F(i, l, r) for (ll i = (l); i < (r); ++i)
vector<pl> adj[NN];
struct mp {
    ll plen = 0, pwe = 0;
    map<ll, ll> mp; // maps weight -> lens, lazy updates and shit

    void insert(ll k, ll w) {
        k -= pwe; w -= plen;
        if (!mp.count(k)) mp[k] = w;
        else mp[k] = min(w, mp[k]);
    }

    ll query(ll k) {
        k -= pwe;
        if (!mp.count(k)) return 1e9;
        return mp[k] + plen;
    }

    vector<pl> getall() const {
        vector<pl> res;
        for (const auto &[k, v]: mp) res.emplace_back(k + pwe, v + plen);
        return res;
    }
};
ll ans, k;

mp dfs(ll i, ll p) {
    mp cur;
    for (auto [x, w]: adj[i]) if (x-p) {
        auto child = dfs(x, i);
        child.plen++; child.pwe+=w;
        ans = min(ans, child.query(k)); 

        if (cur.mp.size() < child.mp.size()) swap(cur, child);
        for (const auto [cpath, clen]: child.getall()) {

            ans = min(ans, cur.query(k - cpath) + clen);
            cur.insert(cpath, clen);
        }
    }

    cur.insert(0, 0);
    return cur;
}

int best_path(int N, int K, int H[][2], int L[])
{
    F(i, 0, N-1) {
        adj[H[i][0]].emplace_back(H[i][1], L[i]);
        adj[H[i][1]].emplace_back(H[i][0], L[i]);
    }

    ans = N;
    k = K;

    dfs(0, 0);

    return ans == N ? -1: ans;
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 8792 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Correct 1 ms 8796 KB Output is correct
4 Correct 1 ms 8796 KB Output is correct
5 Correct 1 ms 8796 KB Output is correct
6 Correct 1 ms 8796 KB Output is correct
7 Correct 1 ms 8796 KB Output is correct
8 Correct 1 ms 8796 KB Output is correct
9 Correct 1 ms 8796 KB Output is correct
10 Correct 1 ms 8796 KB Output is correct
11 Correct 1 ms 8796 KB Output is correct
12 Correct 1 ms 8796 KB Output is correct
13 Correct 1 ms 8796 KB Output is correct
14 Correct 1 ms 8796 KB Output is correct
15 Correct 2 ms 8796 KB Output is correct
16 Correct 2 ms 8792 KB Output is correct
17 Correct 1 ms 8796 KB Output is correct
18 Correct 2 ms 8796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8792 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Correct 1 ms 8796 KB Output is correct
4 Correct 1 ms 8796 KB Output is correct
5 Correct 1 ms 8796 KB Output is correct
6 Correct 1 ms 8796 KB Output is correct
7 Correct 1 ms 8796 KB Output is correct
8 Correct 1 ms 8796 KB Output is correct
9 Correct 1 ms 8796 KB Output is correct
10 Correct 1 ms 8796 KB Output is correct
11 Correct 1 ms 8796 KB Output is correct
12 Correct 1 ms 8796 KB Output is correct
13 Correct 1 ms 8796 KB Output is correct
14 Correct 1 ms 8796 KB Output is correct
15 Correct 2 ms 8796 KB Output is correct
16 Correct 2 ms 8792 KB Output is correct
17 Correct 1 ms 8796 KB Output is correct
18 Correct 2 ms 8796 KB Output is correct
19 Correct 2 ms 8536 KB Output is correct
20 Correct 1 ms 8540 KB Output is correct
21 Correct 2 ms 8796 KB Output is correct
22 Correct 2 ms 8796 KB Output is correct
23 Correct 3 ms 8796 KB Output is correct
24 Correct 2 ms 8796 KB Output is correct
25 Correct 2 ms 8796 KB Output is correct
26 Correct 2 ms 8796 KB Output is correct
27 Correct 2 ms 8796 KB Output is correct
28 Correct 2 ms 8796 KB Output is correct
29 Correct 2 ms 8792 KB Output is correct
30 Correct 2 ms 8796 KB Output is correct
31 Correct 2 ms 8796 KB Output is correct
32 Correct 2 ms 8796 KB Output is correct
33 Correct 2 ms 8868 KB Output is correct
34 Correct 2 ms 8796 KB Output is correct
35 Correct 2 ms 8992 KB Output is correct
36 Correct 2 ms 8796 KB Output is correct
37 Correct 2 ms 8796 KB Output is correct
38 Correct 2 ms 8796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8792 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Correct 1 ms 8796 KB Output is correct
4 Correct 1 ms 8796 KB Output is correct
5 Correct 1 ms 8796 KB Output is correct
6 Correct 1 ms 8796 KB Output is correct
7 Correct 1 ms 8796 KB Output is correct
8 Correct 1 ms 8796 KB Output is correct
9 Correct 1 ms 8796 KB Output is correct
10 Correct 1 ms 8796 KB Output is correct
11 Correct 1 ms 8796 KB Output is correct
12 Correct 1 ms 8796 KB Output is correct
13 Correct 1 ms 8796 KB Output is correct
14 Correct 1 ms 8796 KB Output is correct
15 Correct 2 ms 8796 KB Output is correct
16 Correct 2 ms 8792 KB Output is correct
17 Correct 1 ms 8796 KB Output is correct
18 Correct 2 ms 8796 KB Output is correct
19 Correct 61 ms 16128 KB Output is correct
20 Correct 64 ms 16192 KB Output is correct
21 Correct 63 ms 15956 KB Output is correct
22 Correct 62 ms 16156 KB Output is correct
23 Correct 88 ms 16724 KB Output is correct
24 Correct 68 ms 15780 KB Output is correct
25 Correct 69 ms 34640 KB Output is correct
26 Correct 57 ms 50004 KB Output is correct
27 Correct 117 ms 22004 KB Output is correct
28 Correct 194 ms 101516 KB Output is correct
29 Correct 201 ms 97488 KB Output is correct
30 Correct 115 ms 22096 KB Output is correct
31 Correct 128 ms 22360 KB Output is correct
32 Correct 124 ms 22320 KB Output is correct
33 Correct 127 ms 21844 KB Output is correct
34 Correct 206 ms 35068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8792 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Correct 1 ms 8796 KB Output is correct
4 Correct 1 ms 8796 KB Output is correct
5 Correct 1 ms 8796 KB Output is correct
6 Correct 1 ms 8796 KB Output is correct
7 Correct 1 ms 8796 KB Output is correct
8 Correct 1 ms 8796 KB Output is correct
9 Correct 1 ms 8796 KB Output is correct
10 Correct 1 ms 8796 KB Output is correct
11 Correct 1 ms 8796 KB Output is correct
12 Correct 1 ms 8796 KB Output is correct
13 Correct 1 ms 8796 KB Output is correct
14 Correct 1 ms 8796 KB Output is correct
15 Correct 2 ms 8796 KB Output is correct
16 Correct 2 ms 8792 KB Output is correct
17 Correct 1 ms 8796 KB Output is correct
18 Correct 2 ms 8796 KB Output is correct
19 Correct 2 ms 8536 KB Output is correct
20 Correct 1 ms 8540 KB Output is correct
21 Correct 2 ms 8796 KB Output is correct
22 Correct 2 ms 8796 KB Output is correct
23 Correct 3 ms 8796 KB Output is correct
24 Correct 2 ms 8796 KB Output is correct
25 Correct 2 ms 8796 KB Output is correct
26 Correct 2 ms 8796 KB Output is correct
27 Correct 2 ms 8796 KB Output is correct
28 Correct 2 ms 8796 KB Output is correct
29 Correct 2 ms 8792 KB Output is correct
30 Correct 2 ms 8796 KB Output is correct
31 Correct 2 ms 8796 KB Output is correct
32 Correct 2 ms 8796 KB Output is correct
33 Correct 2 ms 8868 KB Output is correct
34 Correct 2 ms 8796 KB Output is correct
35 Correct 2 ms 8992 KB Output is correct
36 Correct 2 ms 8796 KB Output is correct
37 Correct 2 ms 8796 KB Output is correct
38 Correct 2 ms 8796 KB Output is correct
39 Correct 61 ms 16128 KB Output is correct
40 Correct 64 ms 16192 KB Output is correct
41 Correct 63 ms 15956 KB Output is correct
42 Correct 62 ms 16156 KB Output is correct
43 Correct 88 ms 16724 KB Output is correct
44 Correct 68 ms 15780 KB Output is correct
45 Correct 69 ms 34640 KB Output is correct
46 Correct 57 ms 50004 KB Output is correct
47 Correct 117 ms 22004 KB Output is correct
48 Correct 194 ms 101516 KB Output is correct
49 Correct 201 ms 97488 KB Output is correct
50 Correct 115 ms 22096 KB Output is correct
51 Correct 128 ms 22360 KB Output is correct
52 Correct 124 ms 22320 KB Output is correct
53 Correct 127 ms 21844 KB Output is correct
54 Correct 206 ms 35068 KB Output is correct
55 Correct 11 ms 9564 KB Output is correct
56 Correct 6 ms 9308 KB Output is correct
57 Incorrect 42 ms 16472 KB Output isn't correct
58 Halted 0 ms 0 KB -