답안 #1056404

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1056404 2024-08-13T09:16:46 Z Ignut 가장 긴 여행 (IOI23_longesttrip) C++17
40 / 100
751 ms 1560 KB
/* Ignut
started: 13.08.2024
now: 13.08.2024
████████████████████████████████████████████████████████████████████
████████████████████████████████    ████████████████████████████████
██████████████████████████████        ██████████████████████████████
██████      ██████████████████        ██████████████████      ██████
██████          ██████████████        ██████████████          ██████
██████      ██    ████████████        ████████████    ██      ██████
██████      ████    ██████████        ██████████    ████      ██████
██████      ████      ██████████    ██████████      ████      ██████
██████      ████      ██████████    ██████████    ██████      ██████
██████      ██████    ██████████    ██████████    ██████      ██████
██████      ██████    ████████        ████████    ██████      ██████
██████      ██████      ██████        ██████      ██████      ██████
██████      ████        ████            ████        ████      ██████
██████            ██████████    ████    ██████████            ██████
██████      ██      ██████    ████████    ██████      ██      ██████
██████      ██████            ████████            ██████      ██████
██████                    ██            ██                    ██████
██████████████████████      ████    ████      ██████████████████████
████████████████████████      ██    ██      ████████████████████████
██████████████████████████                ██████████████████████████
██████████████████████████████        ██████████████████████████████
████████████████████████████████████████████████████████████████████
*/

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

bool are_connected(vector<int> A, vector<int> B);

const int MAXN = 333;

vector<int> g[MAXN];
bool used[MAXN];

vector<int> order;

void dfs(int v) {
    order.push_back(v);
    used[v] = true;
    for (int to : g[v]) {
        if (used[to]) continue;
        dfs(to);
        return;
    }
}

vector<int> longest_trip(int N, int D) {
    if (D == 3) {
        vector<int> vec;
        for (int i = 0; i < N; i ++) vec.push_back(i);
        return vec;
    }
    if (D == 2) {
        vector<pair<int, int>> lst;
        int cnt[N] = {};
        for (int i = 0; i < N; i ++) {
            for (int j = i + 1; j < N; j ++) {
                if (!are_connected({i}, {j})) {
                    lst.push_back({i, j});
                    cnt[i] ++, cnt[j] ++;
                }
            }
        }
        vector<int> free;
        for (int i = 0; i < N; i ++) if (cnt[i] == 0) free.push_back(i);
        vector<int> res;
        for (int i = 0; i < lst.size(); i ++) res.push_back(lst[i].first);
        for (int val : free) res.push_back(val);
        for (int i = 0; i < lst.size(); i ++) res.push_back(lst[i].second);
        return res;
    }

    order.clear();
    for (int i = 0; i < N; i ++) {
        g[i].clear();
        used[i] = false;
    }

    for (int i = 0; i < N; i ++) {
        for (int j = i + 1; j < N; j ++) {
            if (are_connected({i}, {j})) {
                g[i].push_back(j);
                g[j].push_back(i);
            }
        }
    }

    vector<int> res;
    for (int start = 0; start < N; start ++) {
        for (int i= 0; i < N; i ++) used[i] = false;
        order.clear();
        dfs(start);
        if (order.size() > res.size()) res = order;
    }
    return res;
}

Compilation message

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:72:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |         for (int i = 0; i < lst.size(); i ++) res.push_back(lst[i].first);
      |                         ~~^~~~~~~~~~~~
longesttrip.cpp:74:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |         for (int i = 0; i < lst.size(); i ++) res.push_back(lst[i].second);
      |                         ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 175 ms 1044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 340 KB Output is correct
2 Correct 22 ms 344 KB Output is correct
3 Correct 124 ms 344 KB Output is correct
4 Correct 330 ms 344 KB Output is correct
5 Correct 700 ms 420 KB Output is correct
6 Correct 4 ms 344 KB Output is correct
7 Correct 19 ms 344 KB Output is correct
8 Correct 118 ms 344 KB Output is correct
9 Correct 258 ms 344 KB Output is correct
10 Correct 673 ms 592 KB Output is correct
11 Correct 719 ms 592 KB Output is correct
12 Correct 657 ms 420 KB Output is correct
13 Correct 725 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 22 ms 344 KB Output is correct
3 Correct 133 ms 344 KB Output is correct
4 Correct 339 ms 460 KB Output is correct
5 Correct 694 ms 868 KB Output is correct
6 Correct 5 ms 344 KB Output is correct
7 Correct 13 ms 344 KB Output is correct
8 Correct 116 ms 452 KB Output is correct
9 Correct 270 ms 708 KB Output is correct
10 Correct 704 ms 1048 KB Output is correct
11 Correct 725 ms 744 KB Output is correct
12 Correct 746 ms 1104 KB Output is correct
13 Correct 725 ms 1132 KB Output is correct
14 Correct 8 ms 344 KB Output is correct
15 Correct 9 ms 344 KB Output is correct
16 Correct 29 ms 344 KB Output is correct
17 Correct 60 ms 344 KB Output is correct
18 Correct 115 ms 600 KB Output is correct
19 Correct 270 ms 712 KB Output is correct
20 Correct 249 ms 728 KB Output is correct
21 Correct 734 ms 1112 KB Output is correct
22 Correct 738 ms 696 KB Output is correct
23 Correct 718 ms 720 KB Output is correct
24 Correct 739 ms 884 KB Output is correct
25 Correct 5 ms 344 KB Output is correct
26 Correct 7 ms 344 KB Output is correct
27 Correct 18 ms 344 KB Output is correct
28 Correct 19 ms 344 KB Output is correct
29 Correct 24 ms 344 KB Output is correct
30 Correct 165 ms 600 KB Output is correct
31 Correct 177 ms 600 KB Output is correct
32 Correct 148 ms 344 KB Output is correct
33 Correct 248 ms 492 KB Output is correct
34 Correct 254 ms 344 KB Output is correct
35 Correct 269 ms 1104 KB Output is correct
36 Correct 717 ms 860 KB Output is correct
37 Correct 593 ms 1052 KB Output is correct
38 Correct 707 ms 944 KB Output is correct
39 Correct 635 ms 1100 KB Output is correct
40 Correct 729 ms 1184 KB Output is correct
41 Correct 679 ms 996 KB Output is correct
42 Correct 733 ms 600 KB Output is correct
43 Correct 692 ms 1392 KB Output is correct
44 Correct 705 ms 1188 KB Output is correct
45 Correct 6 ms 344 KB Output is correct
46 Correct 6 ms 344 KB Output is correct
47 Correct 21 ms 344 KB Output is correct
48 Correct 15 ms 344 KB Output is correct
49 Correct 23 ms 344 KB Output is correct
50 Correct 144 ms 344 KB Output is correct
51 Correct 180 ms 596 KB Output is correct
52 Correct 194 ms 592 KB Output is correct
53 Correct 253 ms 600 KB Output is correct
54 Correct 258 ms 596 KB Output is correct
55 Correct 265 ms 476 KB Output is correct
56 Correct 696 ms 944 KB Output is correct
57 Correct 749 ms 996 KB Output is correct
58 Correct 747 ms 1560 KB Output is correct
59 Correct 738 ms 936 KB Output is correct
60 Correct 741 ms 1176 KB Output is correct
61 Correct 747 ms 768 KB Output is correct
62 Correct 722 ms 780 KB Output is correct
63 Correct 572 ms 712 KB Output is correct
64 Correct 713 ms 968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 23 ms 344 KB Output is correct
3 Partially correct 114 ms 600 KB Output is partially correct
4 Partially correct 377 ms 476 KB Output is partially correct
5 Partially correct 692 ms 972 KB Output is partially correct
6 Correct 7 ms 344 KB Output is correct
7 Correct 22 ms 344 KB Output is correct
8 Partially correct 122 ms 344 KB Output is partially correct
9 Partially correct 297 ms 596 KB Output is partially correct
10 Partially correct 751 ms 864 KB Output is partially correct
11 Partially correct 717 ms 860 KB Output is partially correct
12 Partially correct 715 ms 1288 KB Output is partially correct
13 Partially correct 742 ms 888 KB Output is partially correct
14 Correct 10 ms 344 KB Output is correct
15 Correct 10 ms 344 KB Output is correct
16 Incorrect 6 ms 344 KB Incorrect
17 Halted 0 ms 0 KB -