답안 #841273

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
841273 2023-09-01T12:28:49 Z I_love_Hoang_Yen 가장 긴 여행 (IOI23_longesttrip) C++17
40 / 100
13 ms 332 KB
#include "longesttrip.h"
#include <bits/stdc++.h>
using namespace std;

// Subtask 1: D == 3
vector<int> sub1(int n) {
    vector<int> res(n);
    std::iota(res.begin(), res.end(), 0);
    return res;
}

// Subtask 2: D == 2
vector<int> sub2(int n) {
    vector<int> res {0};
    for (int i = 1; i < n; i++) {
        if (are_connected({0}, {i})) {
            res.push_back(i);
            break;
        }
    }

    for (int i = 1; i < n; i++) {
        if (i == res[1]) continue;

        if (are_connected({res.back()}, {i})) {
            res.push_back(i);
        } else {
            res.insert(res.begin(), i);
        }
    }

    return res;
}

// Subtask 3: D == 1, return path with length >= Lmax / 2
vector<int> sub3(int n) {
    // maintain 2 paths
    vector<int> p1 {0}, p2 {1};

    for (int i = 2; i < n; ++i) {
        // consider p1.back(), p2.back(), i
        // -> there's at least 1 edge

        if (are_connected({p1.back()}, {i})) {
            p1.push_back(i);
        } else if (are_connected({p2.back()}, {i})) {
            p2.push_back(i);
        } else {
            reverse(p2.begin(), p2.end());
            p1.insert(p1.end(), p2.begin(), p2.end());
            p2 = {i};
        }
    }
    if (p1.size() > p2.size()) return p1;
    return p2;
}

vector<int> longest_trip(int n, int d) {
    if (d == 3) return sub1(n);
    if (d == 2) return sub2(n);
    return sub3(n);
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 208 KB Incorrect
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 208 KB Output is correct
2 Correct 13 ms 208 KB Output is correct
3 Correct 9 ms 208 KB Output is correct
4 Correct 10 ms 208 KB Output is correct
5 Correct 8 ms 300 KB Output is correct
6 Correct 9 ms 260 KB Output is correct
7 Correct 8 ms 208 KB Output is correct
8 Correct 10 ms 208 KB Output is correct
9 Correct 7 ms 208 KB Output is correct
10 Correct 9 ms 324 KB Output is correct
11 Correct 6 ms 208 KB Output is correct
12 Correct 10 ms 208 KB Output is correct
13 Correct 9 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 208 KB Output is correct
2 Correct 7 ms 208 KB Output is correct
3 Correct 9 ms 208 KB Output is correct
4 Correct 5 ms 208 KB Output is correct
5 Correct 7 ms 208 KB Output is correct
6 Correct 8 ms 208 KB Output is correct
7 Correct 9 ms 208 KB Output is correct
8 Correct 8 ms 208 KB Output is correct
9 Correct 11 ms 208 KB Output is correct
10 Correct 6 ms 208 KB Output is correct
11 Correct 6 ms 208 KB Output is correct
12 Correct 6 ms 208 KB Output is correct
13 Correct 9 ms 208 KB Output is correct
14 Correct 5 ms 208 KB Output is correct
15 Correct 10 ms 208 KB Output is correct
16 Correct 9 ms 208 KB Output is correct
17 Correct 9 ms 208 KB Output is correct
18 Correct 11 ms 208 KB Output is correct
19 Correct 6 ms 208 KB Output is correct
20 Correct 7 ms 208 KB Output is correct
21 Correct 10 ms 208 KB Output is correct
22 Correct 11 ms 208 KB Output is correct
23 Correct 9 ms 208 KB Output is correct
24 Correct 6 ms 208 KB Output is correct
25 Correct 8 ms 208 KB Output is correct
26 Correct 9 ms 208 KB Output is correct
27 Correct 9 ms 208 KB Output is correct
28 Correct 6 ms 208 KB Output is correct
29 Correct 8 ms 208 KB Output is correct
30 Correct 6 ms 208 KB Output is correct
31 Correct 9 ms 208 KB Output is correct
32 Correct 12 ms 208 KB Output is correct
33 Correct 7 ms 208 KB Output is correct
34 Correct 7 ms 332 KB Output is correct
35 Correct 8 ms 208 KB Output is correct
36 Correct 7 ms 208 KB Output is correct
37 Correct 9 ms 332 KB Output is correct
38 Correct 10 ms 208 KB Output is correct
39 Correct 6 ms 208 KB Output is correct
40 Correct 8 ms 288 KB Output is correct
41 Correct 11 ms 208 KB Output is correct
42 Correct 11 ms 260 KB Output is correct
43 Correct 11 ms 208 KB Output is correct
44 Correct 13 ms 208 KB Output is correct
45 Correct 6 ms 208 KB Output is correct
46 Correct 8 ms 208 KB Output is correct
47 Correct 8 ms 208 KB Output is correct
48 Correct 8 ms 208 KB Output is correct
49 Correct 8 ms 208 KB Output is correct
50 Correct 8 ms 208 KB Output is correct
51 Correct 9 ms 208 KB Output is correct
52 Correct 10 ms 208 KB Output is correct
53 Correct 5 ms 208 KB Output is correct
54 Correct 7 ms 208 KB Output is correct
55 Correct 8 ms 208 KB Output is correct
56 Correct 7 ms 208 KB Output is correct
57 Correct 10 ms 208 KB Output is correct
58 Correct 9 ms 208 KB Output is correct
59 Correct 10 ms 208 KB Output is correct
60 Correct 11 ms 208 KB Output is correct
61 Correct 10 ms 332 KB Output is correct
62 Correct 12 ms 208 KB Output is correct
63 Correct 10 ms 208 KB Output is correct
64 Correct 12 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 208 KB Incorrect
2 Halted 0 ms 0 KB -