답안 #1056467

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

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

mt19937 rnd(11223344);

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);
            }
        }
    }

    for (int i = 0; i < N; i ++) {
        shuffle(g[i].begin(), g[i].end(), rnd);
    }

    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: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].first);
      |                         ~~^~~~~~~~~~~~
longesttrip.cpp:76: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]
   76 |         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 191 ms 716 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 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 344 KB Output is correct
2 Correct 23 ms 344 KB Output is correct
3 Correct 114 ms 344 KB Output is correct
4 Correct 349 ms 344 KB Output is correct
5 Correct 707 ms 420 KB Output is correct
6 Correct 9 ms 344 KB Output is correct
7 Correct 16 ms 344 KB Output is correct
8 Correct 108 ms 344 KB Output is correct
9 Correct 226 ms 344 KB Output is correct
10 Correct 679 ms 424 KB Output is correct
11 Correct 666 ms 592 KB Output is correct
12 Correct 698 ms 420 KB Output is correct
13 Correct 661 ms 420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 344 KB Output is correct
2 Correct 23 ms 344 KB Output is correct
3 Correct 120 ms 600 KB Output is correct
4 Correct 316 ms 856 KB Output is correct
5 Correct 677 ms 1120 KB Output is correct
6 Correct 5 ms 344 KB Output is correct
7 Correct 18 ms 344 KB Output is correct
8 Correct 99 ms 344 KB Output is correct
9 Correct 238 ms 344 KB Output is correct
10 Correct 720 ms 716 KB Output is correct
11 Correct 711 ms 808 KB Output is correct
12 Correct 680 ms 900 KB Output is correct
13 Correct 674 ms 736 KB Output is correct
14 Correct 8 ms 344 KB Output is correct
15 Correct 13 ms 344 KB Output is correct
16 Correct 25 ms 344 KB Output is correct
17 Correct 75 ms 344 KB Output is correct
18 Correct 130 ms 344 KB Output is correct
19 Correct 267 ms 488 KB Output is correct
20 Correct 245 ms 596 KB Output is correct
21 Correct 677 ms 1148 KB Output is correct
22 Correct 747 ms 800 KB Output is correct
23 Correct 700 ms 1104 KB Output is correct
24 Correct 728 ms 1012 KB Output is correct
25 Correct 7 ms 344 KB Output is correct
26 Correct 10 ms 344 KB Output is correct
27 Correct 18 ms 344 KB Output is correct
28 Correct 18 ms 344 KB Output is correct
29 Correct 18 ms 344 KB Output is correct
30 Correct 156 ms 456 KB Output is correct
31 Correct 186 ms 592 KB Output is correct
32 Correct 155 ms 344 KB Output is correct
33 Correct 275 ms 344 KB Output is correct
34 Correct 263 ms 472 KB Output is correct
35 Correct 266 ms 484 KB Output is correct
36 Correct 675 ms 1232 KB Output is correct
37 Correct 684 ms 860 KB Output is correct
38 Correct 648 ms 952 KB Output is correct
39 Correct 717 ms 1432 KB Output is correct
40 Correct 736 ms 748 KB Output is correct
41 Correct 722 ms 728 KB Output is correct
42 Correct 694 ms 460 KB Output is correct
43 Correct 649 ms 1104 KB Output is correct
44 Correct 678 ms 1004 KB Output is correct
45 Correct 7 ms 344 KB Output is correct
46 Correct 7 ms 344 KB Output is correct
47 Correct 28 ms 592 KB Output is correct
48 Correct 23 ms 344 KB Output is correct
49 Correct 22 ms 344 KB Output is correct
50 Correct 161 ms 344 KB Output is correct
51 Correct 150 ms 344 KB Output is correct
52 Correct 152 ms 444 KB Output is correct
53 Correct 272 ms 600 KB Output is correct
54 Correct 244 ms 344 KB Output is correct
55 Correct 255 ms 344 KB Output is correct
56 Correct 718 ms 1072 KB Output is correct
57 Correct 670 ms 996 KB Output is correct
58 Correct 699 ms 956 KB Output is correct
59 Correct 702 ms 716 KB Output is correct
60 Correct 642 ms 972 KB Output is correct
61 Correct 708 ms 736 KB Output is correct
62 Correct 664 ms 1256 KB Output is correct
63 Correct 636 ms 1160 KB Output is correct
64 Correct 658 ms 1268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 20 ms 344 KB Output is correct
3 Partially correct 129 ms 344 KB Output is partially correct
4 Partially correct 342 ms 732 KB Output is partially correct
5 Partially correct 650 ms 908 KB Output is partially correct
6 Correct 6 ms 344 KB Output is correct
7 Correct 21 ms 344 KB Output is correct
8 Partially correct 120 ms 344 KB Output is partially correct
9 Partially correct 286 ms 852 KB Output is partially correct
10 Partially correct 662 ms 1164 KB Output is partially correct
11 Partially correct 690 ms 748 KB Output is partially correct
12 Partially correct 725 ms 1128 KB Output is partially correct
13 Partially correct 716 ms 968 KB Output is partially correct
14 Correct 8 ms 344 KB Output is correct
15 Correct 9 ms 344 KB Output is correct
16 Incorrect 36 ms 344 KB Incorrect
17 Halted 0 ms 0 KB -