답안 #689943

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
689943 2023-01-29T20:27:50 Z Patrick 경주 (Race) (IOI11_race) C++17
21 / 100
106 ms 7532 KB
#include "race.h"

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

unordered_map<ll, int> solve(int N, ll K, vector<vector<pair<int, int>>>& es,
                             int& curmin, int last, int cur) {
    // cout << "solve " << cur << "\n";
    unordered_map<ll, int> ans;
    ans.insert({0, 0});

    for (auto [next, len] : es[cur]) {
        if (next == last) continue;
        unordered_map<ll, int> a = solve(N, K, es, curmin, cur, next);

        for (auto [k, v] : a) {
            if (k > K) continue;
            ll search = K - (k + (ll)len);
            auto it = ans.find(search);
            if (it != ans.end()) {
                curmin = min(curmin, it->second + v + 1);
            }
        }
        for (auto [k, v] : a) {
            if (k > K) continue;
            ans.insert({k + (ll)len, v + 1});
        }
    }
    return ans;
}

int best_path(int N, int K, int H[][2], int L[]) {
    // cout << "testcase\n";
    vector<vector<pair<int, int>>> es(N);
    for (int i = 0; i < N - 1; i++) {
        es[H[i][0]].push_back({H[i][1], L[i]});
        es[H[i][1]].push_back({H[i][0], L[i]});
    }
    int curmin = N;
    auto ans = solve(N, K, es, curmin, -1, 0);
    if (curmin == N) {
        return -1;
    } else {
        return curmin;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 2 ms 452 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 3 ms 468 KB Output is correct
34 Correct 2 ms 340 KB Output is correct
35 Correct 3 ms 468 KB Output is correct
36 Correct 3 ms 468 KB Output is correct
37 Correct 8 ms 468 KB Output is correct
38 Correct 7 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 106 ms 7528 KB Output is correct
20 Correct 97 ms 7532 KB Output is correct
21 Incorrect 96 ms 7464 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 2 ms 452 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 3 ms 468 KB Output is correct
34 Correct 2 ms 340 KB Output is correct
35 Correct 3 ms 468 KB Output is correct
36 Correct 3 ms 468 KB Output is correct
37 Correct 8 ms 468 KB Output is correct
38 Correct 7 ms 468 KB Output is correct
39 Correct 106 ms 7528 KB Output is correct
40 Correct 97 ms 7532 KB Output is correct
41 Incorrect 96 ms 7464 KB Output isn't correct
42 Halted 0 ms 0 KB -