답안 #728019

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
728019 2023-04-21T19:30:04 Z CutSandstone 경주 (Race) (IOI11_race) C++17
100 / 100
392 ms 86920 KB
#include <bits/stdc++.h>
#include "race.h"
#define ll long long
#define f first
#define s second
#define pb push_back
#define mod 1000000007
#define maxN 200000
using namespace std;
void setio(string name = "") {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    // if(name.length()) {
    //     freopen((name + ".in").c_str(), "r", stdin);
    //     freopen((name + ".out").c_str(), "w", stdout);
    // }
}
class AddMap {
    public:
        unordered_map<int, int> mp;
        int add1, add2;
        AddMap(){
            add1 = 0;
            add2 = 0;
            mp.clear();
        }
        vector<pair<int, int>> iter(){
            vector<pair<int, int>> ret(mp.size());
            for(auto i: mp) ret.pb({i.f+add1, i.s+add2});
            return ret;
        }
        int get(int num){
            return mp.find(num-add1) == mp.end() ? -1:mp[num-add1]+add2;
        }
        void put(int num, int val){
            mp[num-add1] = val-add2;
        }
        void addKey(int num){
            add1+=num;
        }
        void addVal(int num){
            add2+=num;
        }
        int size(){
            return mp.size();
        }
};
int N, K, ans = 1<<30;
vector<pair<int, int>> g[maxN];
AddMap* dfs(int s, int p){
    AddMap* ret = new AddMap();
    for(pair<int, int> e: g[s]) if(e.f != p){
        AddMap* get = dfs(e.f, s);
        get->put(0, 0);
        get->addKey(e.s);
        get->addVal(1);
        int up = get->get(K);
        if(up != -1) ans = min(ans, up);
        if(get->size() > ret->size()){
            AddMap* save = get;
            get = ret;
            ret = save;
        }
        vector<pair<int, int>> v = get->iter();
        for(pair<int, int> c: v){
            int curr = ret->get(K-c.f);
            if(curr != -1) ans = min(ans, c.s+curr);
        }
        for(pair<int, int> c: v){
            int curr = ret->get(c.f);
            if(curr == -1 || curr > c.s) ret->put(c.f, c.s);
        }
    }
    return ret;
}
int best_path(int a, int b, int h[][2], int l[]){
    N = a;
    K = b;
    ans = 1<<30;
    for(int i = 0; i<N; i++) g[i].clear();
    for(int i = 0; i<N-1; i++){
        g[h[i][0]].pb({h[i][1], l[i]});
        g[h[i][1]].pb({h[i][0], l[i]});
    }
    dfs(0, -1);
    if(ans == 1<<30) return -1;
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 4 ms 5008 KB Output is correct
5 Correct 4 ms 5012 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 5008 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 5012 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 5008 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 5004 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 5008 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 5004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 4 ms 5008 KB Output is correct
5 Correct 4 ms 5012 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 5008 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 5012 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 5008 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 5004 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 5008 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 5004 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 4 ms 5204 KB Output is correct
22 Correct 4 ms 5272 KB Output is correct
23 Correct 4 ms 5332 KB Output is correct
24 Correct 4 ms 5272 KB Output is correct
25 Correct 4 ms 5332 KB Output is correct
26 Correct 4 ms 5332 KB Output is correct
27 Correct 4 ms 5204 KB Output is correct
28 Correct 4 ms 5332 KB Output is correct
29 Correct 3 ms 5332 KB Output is correct
30 Correct 4 ms 5276 KB Output is correct
31 Correct 4 ms 5332 KB Output is correct
32 Correct 4 ms 5332 KB Output is correct
33 Correct 4 ms 5332 KB Output is correct
34 Correct 4 ms 5204 KB Output is correct
35 Correct 4 ms 5204 KB Output is correct
36 Correct 3 ms 5204 KB Output is correct
37 Correct 3 ms 5144 KB Output is correct
38 Correct 4 ms 5148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 4 ms 5008 KB Output is correct
5 Correct 4 ms 5012 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 5008 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 5012 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 5008 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 5004 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 5008 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 5004 KB Output is correct
19 Correct 110 ms 30048 KB Output is correct
20 Correct 103 ms 30120 KB Output is correct
21 Correct 113 ms 30156 KB Output is correct
22 Correct 109 ms 30880 KB Output is correct
23 Correct 155 ms 39376 KB Output is correct
24 Correct 131 ms 38328 KB Output is correct
25 Correct 60 ms 26388 KB Output is correct
26 Correct 51 ms 32508 KB Output is correct
27 Correct 195 ms 51940 KB Output is correct
28 Correct 190 ms 69892 KB Output is correct
29 Correct 156 ms 68468 KB Output is correct
30 Correct 202 ms 51836 KB Output is correct
31 Correct 179 ms 51916 KB Output is correct
32 Correct 204 ms 52052 KB Output is correct
33 Correct 171 ms 41132 KB Output is correct
34 Correct 259 ms 64136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 4 ms 5008 KB Output is correct
5 Correct 4 ms 5012 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 5008 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 5012 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 5008 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 5004 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 5008 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 5004 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 4 ms 5204 KB Output is correct
22 Correct 4 ms 5272 KB Output is correct
23 Correct 4 ms 5332 KB Output is correct
24 Correct 4 ms 5272 KB Output is correct
25 Correct 4 ms 5332 KB Output is correct
26 Correct 4 ms 5332 KB Output is correct
27 Correct 4 ms 5204 KB Output is correct
28 Correct 4 ms 5332 KB Output is correct
29 Correct 3 ms 5332 KB Output is correct
30 Correct 4 ms 5276 KB Output is correct
31 Correct 4 ms 5332 KB Output is correct
32 Correct 4 ms 5332 KB Output is correct
33 Correct 4 ms 5332 KB Output is correct
34 Correct 4 ms 5204 KB Output is correct
35 Correct 4 ms 5204 KB Output is correct
36 Correct 3 ms 5204 KB Output is correct
37 Correct 3 ms 5144 KB Output is correct
38 Correct 4 ms 5148 KB Output is correct
39 Correct 110 ms 30048 KB Output is correct
40 Correct 103 ms 30120 KB Output is correct
41 Correct 113 ms 30156 KB Output is correct
42 Correct 109 ms 30880 KB Output is correct
43 Correct 155 ms 39376 KB Output is correct
44 Correct 131 ms 38328 KB Output is correct
45 Correct 60 ms 26388 KB Output is correct
46 Correct 51 ms 32508 KB Output is correct
47 Correct 195 ms 51940 KB Output is correct
48 Correct 190 ms 69892 KB Output is correct
49 Correct 156 ms 68468 KB Output is correct
50 Correct 202 ms 51836 KB Output is correct
51 Correct 179 ms 51916 KB Output is correct
52 Correct 204 ms 52052 KB Output is correct
53 Correct 171 ms 41132 KB Output is correct
54 Correct 259 ms 64136 KB Output is correct
55 Correct 14 ms 8276 KB Output is correct
56 Correct 14 ms 7236 KB Output is correct
57 Correct 76 ms 29364 KB Output is correct
58 Correct 77 ms 33008 KB Output is correct
59 Correct 59 ms 37216 KB Output is correct
60 Correct 150 ms 68804 KB Output is correct
61 Correct 208 ms 54412 KB Output is correct
62 Correct 188 ms 51868 KB Output is correct
63 Correct 194 ms 51912 KB Output is correct
64 Correct 372 ms 85088 KB Output is correct
65 Correct 392 ms 86920 KB Output is correct
66 Correct 213 ms 66252 KB Output is correct
67 Correct 175 ms 61992 KB Output is correct
68 Correct 313 ms 67512 KB Output is correct
69 Correct 281 ms 71392 KB Output is correct
70 Correct 255 ms 65064 KB Output is correct