Submission #947208

# Submission time Handle Problem Language Result Execution time Memory
947208 2024-03-15T16:03:32 Z steveonalex Race (IOI11_race) C++14
100 / 100
389 ms 102736 KB
#include <bits/stdc++.h>
#include "race.h"
// 

 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define MASK(i) (1ULL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
#define ALL(v) (v).begin(), (v).end()
 
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
 
ll LASTBIT(ll mask){return (mask) & (-mask);}
int pop_cnt(ll mask){return __builtin_popcountll(mask);}
int ctz(ll mask){return __builtin_ctzll(mask);}
int logOf(ll mask){return 63 - __builtin_clzll(mask);}
 
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);}
 
template <class T1, class T2>
    bool maximize(T1 &a, T2 b){
        if (a < b) {a = b; return true;}
        return false;
    }
 
template <class T1, class T2>
    bool minimize(T1 &a, T2 b){
        if (a > b) {a = b; return true;}
        return false;
    }
 
template <class T>
    void printArr(T& container, string separator = " ", string finish = "\n", ostream &out = cout){
        for(auto item: container) out << item << separator;
        out << finish;
    }
 
template <class T>
    void remove_dup(vector<T> &a){
        sort(ALL(a));
        a.resize(unique(ALL(a)) - a.begin());
    }

const int N = 2e5 + 69;
const int INF = 1e9 + 69;
int n, k, ans;
vector<pair<int, int>> graph[N];
map<ll, int> dp[N];

void dfs(int u, int p, int h, ll l){
    dp[u][l] = h;
    for(auto v: graph[u]) if (v.first != p){
        dfs(v.first, u, h + 1, l + v.second);
        if (dp[u].size() < dp[v.first].size()) swap(dp[u], dp[v.first]);
        
        for(auto i: dp[v.first]){
            ll _l = k - (i.first - l) + l;
            if (dp[u].count(_l)) minimize(ans, i.second + dp[u][_l] - 2 * h);

        }
        for(auto i: dp[v.first]) {
            if (dp[u].count(i.first)) minimize(dp[u][i.first], i.second);
            else dp[u][i.first] = i.second;
        }
    }
}

int best_path(int _n, int _k, int H[][2], int L[]){
    n = _n; k = _k, ans = INF;
    for(int i= 0; i<=n; ++i) {
        graph[i].clear();
        dp[i].clear();
    }

    for(int i = 0; i<n-1; ++i){
        int u = H[i][0], v = H[i][1], w = L[i];
        graph[u].push_back({v, w});
        graph[v].push_back({u, w});
    }

    dfs(0, 0, 0, 0);
    if (ans == INF) return -1;
    return ans;
}


// int main(void){
//     ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 
//     return 0;
// }
# Verdict Execution time Memory Grader output
1 Correct 4 ms 18012 KB Output is correct
2 Correct 4 ms 18012 KB Output is correct
3 Correct 5 ms 18012 KB Output is correct
4 Correct 4 ms 18012 KB Output is correct
5 Correct 5 ms 18012 KB Output is correct
6 Correct 4 ms 18012 KB Output is correct
7 Correct 4 ms 18008 KB Output is correct
8 Correct 4 ms 18012 KB Output is correct
9 Correct 4 ms 18008 KB Output is correct
10 Correct 5 ms 18012 KB Output is correct
11 Correct 4 ms 18012 KB Output is correct
12 Correct 4 ms 18012 KB Output is correct
13 Correct 4 ms 18008 KB Output is correct
14 Correct 4 ms 18008 KB Output is correct
15 Correct 4 ms 18008 KB Output is correct
16 Correct 4 ms 18012 KB Output is correct
17 Correct 4 ms 18012 KB Output is correct
18 Correct 4 ms 18012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 18012 KB Output is correct
2 Correct 4 ms 18012 KB Output is correct
3 Correct 5 ms 18012 KB Output is correct
4 Correct 4 ms 18012 KB Output is correct
5 Correct 5 ms 18012 KB Output is correct
6 Correct 4 ms 18012 KB Output is correct
7 Correct 4 ms 18008 KB Output is correct
8 Correct 4 ms 18012 KB Output is correct
9 Correct 4 ms 18008 KB Output is correct
10 Correct 5 ms 18012 KB Output is correct
11 Correct 4 ms 18012 KB Output is correct
12 Correct 4 ms 18012 KB Output is correct
13 Correct 4 ms 18008 KB Output is correct
14 Correct 4 ms 18008 KB Output is correct
15 Correct 4 ms 18008 KB Output is correct
16 Correct 4 ms 18012 KB Output is correct
17 Correct 4 ms 18012 KB Output is correct
18 Correct 4 ms 18012 KB Output is correct
19 Correct 4 ms 18008 KB Output is correct
20 Correct 4 ms 18012 KB Output is correct
21 Correct 5 ms 18268 KB Output is correct
22 Correct 5 ms 18268 KB Output is correct
23 Correct 5 ms 18268 KB Output is correct
24 Correct 5 ms 18264 KB Output is correct
25 Correct 5 ms 18268 KB Output is correct
26 Correct 5 ms 18280 KB Output is correct
27 Correct 4 ms 18268 KB Output is correct
28 Correct 5 ms 18268 KB Output is correct
29 Correct 5 ms 18268 KB Output is correct
30 Correct 5 ms 18268 KB Output is correct
31 Correct 5 ms 18268 KB Output is correct
32 Correct 5 ms 18456 KB Output is correct
33 Correct 5 ms 18268 KB Output is correct
34 Correct 4 ms 18268 KB Output is correct
35 Correct 4 ms 18268 KB Output is correct
36 Correct 5 ms 18268 KB Output is correct
37 Correct 5 ms 18268 KB Output is correct
38 Correct 4 ms 18184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 18012 KB Output is correct
2 Correct 4 ms 18012 KB Output is correct
3 Correct 5 ms 18012 KB Output is correct
4 Correct 4 ms 18012 KB Output is correct
5 Correct 5 ms 18012 KB Output is correct
6 Correct 4 ms 18012 KB Output is correct
7 Correct 4 ms 18008 KB Output is correct
8 Correct 4 ms 18012 KB Output is correct
9 Correct 4 ms 18008 KB Output is correct
10 Correct 5 ms 18012 KB Output is correct
11 Correct 4 ms 18012 KB Output is correct
12 Correct 4 ms 18012 KB Output is correct
13 Correct 4 ms 18008 KB Output is correct
14 Correct 4 ms 18008 KB Output is correct
15 Correct 4 ms 18008 KB Output is correct
16 Correct 4 ms 18012 KB Output is correct
17 Correct 4 ms 18012 KB Output is correct
18 Correct 4 ms 18012 KB Output is correct
19 Correct 90 ms 39788 KB Output is correct
20 Correct 96 ms 40532 KB Output is correct
21 Correct 110 ms 40016 KB Output is correct
22 Correct 90 ms 40272 KB Output is correct
23 Correct 130 ms 53072 KB Output is correct
24 Correct 102 ms 43676 KB Output is correct
25 Correct 78 ms 39764 KB Output is correct
26 Correct 51 ms 46160 KB Output is correct
27 Correct 146 ms 48468 KB Output is correct
28 Correct 224 ms 84424 KB Output is correct
29 Correct 233 ms 83324 KB Output is correct
30 Correct 146 ms 48976 KB Output is correct
31 Correct 144 ms 49072 KB Output is correct
32 Correct 189 ms 48976 KB Output is correct
33 Correct 177 ms 54096 KB Output is correct
34 Correct 269 ms 86544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 18012 KB Output is correct
2 Correct 4 ms 18012 KB Output is correct
3 Correct 5 ms 18012 KB Output is correct
4 Correct 4 ms 18012 KB Output is correct
5 Correct 5 ms 18012 KB Output is correct
6 Correct 4 ms 18012 KB Output is correct
7 Correct 4 ms 18008 KB Output is correct
8 Correct 4 ms 18012 KB Output is correct
9 Correct 4 ms 18008 KB Output is correct
10 Correct 5 ms 18012 KB Output is correct
11 Correct 4 ms 18012 KB Output is correct
12 Correct 4 ms 18012 KB Output is correct
13 Correct 4 ms 18008 KB Output is correct
14 Correct 4 ms 18008 KB Output is correct
15 Correct 4 ms 18008 KB Output is correct
16 Correct 4 ms 18012 KB Output is correct
17 Correct 4 ms 18012 KB Output is correct
18 Correct 4 ms 18012 KB Output is correct
19 Correct 4 ms 18008 KB Output is correct
20 Correct 4 ms 18012 KB Output is correct
21 Correct 5 ms 18268 KB Output is correct
22 Correct 5 ms 18268 KB Output is correct
23 Correct 5 ms 18268 KB Output is correct
24 Correct 5 ms 18264 KB Output is correct
25 Correct 5 ms 18268 KB Output is correct
26 Correct 5 ms 18280 KB Output is correct
27 Correct 4 ms 18268 KB Output is correct
28 Correct 5 ms 18268 KB Output is correct
29 Correct 5 ms 18268 KB Output is correct
30 Correct 5 ms 18268 KB Output is correct
31 Correct 5 ms 18268 KB Output is correct
32 Correct 5 ms 18456 KB Output is correct
33 Correct 5 ms 18268 KB Output is correct
34 Correct 4 ms 18268 KB Output is correct
35 Correct 4 ms 18268 KB Output is correct
36 Correct 5 ms 18268 KB Output is correct
37 Correct 5 ms 18268 KB Output is correct
38 Correct 4 ms 18184 KB Output is correct
39 Correct 90 ms 39788 KB Output is correct
40 Correct 96 ms 40532 KB Output is correct
41 Correct 110 ms 40016 KB Output is correct
42 Correct 90 ms 40272 KB Output is correct
43 Correct 130 ms 53072 KB Output is correct
44 Correct 102 ms 43676 KB Output is correct
45 Correct 78 ms 39764 KB Output is correct
46 Correct 51 ms 46160 KB Output is correct
47 Correct 146 ms 48468 KB Output is correct
48 Correct 224 ms 84424 KB Output is correct
49 Correct 233 ms 83324 KB Output is correct
50 Correct 146 ms 48976 KB Output is correct
51 Correct 144 ms 49072 KB Output is correct
52 Correct 189 ms 48976 KB Output is correct
53 Correct 177 ms 54096 KB Output is correct
54 Correct 269 ms 86544 KB Output is correct
55 Correct 15 ms 21080 KB Output is correct
56 Correct 9 ms 19800 KB Output is correct
57 Correct 57 ms 37160 KB Output is correct
58 Correct 41 ms 31428 KB Output is correct
59 Correct 73 ms 52400 KB Output is correct
60 Correct 214 ms 83744 KB Output is correct
61 Correct 178 ms 51896 KB Output is correct
62 Correct 172 ms 48976 KB Output is correct
63 Correct 202 ms 49488 KB Output is correct
64 Correct 389 ms 102736 KB Output is correct
65 Correct 370 ms 102484 KB Output is correct
66 Correct 236 ms 78508 KB Output is correct
67 Correct 130 ms 44220 KB Output is correct
68 Correct 304 ms 65668 KB Output is correct
69 Correct 359 ms 68608 KB Output is correct
70 Correct 283 ms 64364 KB Output is correct