답안 #689941

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

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

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

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

        for (auto [k, v] : a) {
            int search = K - (k + len);
            auto it = ans.find(search);
            if (it != ans.end()) {
                curmin = min(curmin, it->second + v + 1);
            }
        }
        for (auto [k, v] : a) {
            ans.insert({k + 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 1 ms 312 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 308 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 304 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 304 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 1 ms 312 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 308 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 304 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 304 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 3 ms 436 KB Output is correct
23 Correct 5 ms 468 KB Output is correct
24 Correct 3 ms 516 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 2 ms 448 KB Output is correct
27 Correct 2 ms 316 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 2 ms 468 KB Output is correct
30 Correct 2 ms 448 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
32 Correct 2 ms 468 KB Output is correct
33 Correct 3 ms 468 KB Output is correct
34 Correct 13 ms 532 KB Output is correct
35 Correct 17 ms 468 KB Output is correct
36 Correct 19 ms 468 KB Output is correct
37 Correct 10 ms 448 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 1 ms 312 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 308 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 304 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 304 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 135 ms 8904 KB Output is correct
20 Correct 108 ms 8892 KB Output is correct
21 Incorrect 98 ms 8812 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 1 ms 312 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 308 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 304 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 304 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 3 ms 436 KB Output is correct
23 Correct 5 ms 468 KB Output is correct
24 Correct 3 ms 516 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 2 ms 448 KB Output is correct
27 Correct 2 ms 316 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 2 ms 468 KB Output is correct
30 Correct 2 ms 448 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
32 Correct 2 ms 468 KB Output is correct
33 Correct 3 ms 468 KB Output is correct
34 Correct 13 ms 532 KB Output is correct
35 Correct 17 ms 468 KB Output is correct
36 Correct 19 ms 468 KB Output is correct
37 Correct 10 ms 448 KB Output is correct
38 Correct 7 ms 468 KB Output is correct
39 Correct 135 ms 8904 KB Output is correct
40 Correct 108 ms 8892 KB Output is correct
41 Incorrect 98 ms 8812 KB Output isn't correct
42 Halted 0 ms 0 KB -