Submission #1080912

# Submission time Handle Problem Language Result Execution time Memory
1080912 2024-08-29T15:56:49 Z asdasdqwer Longest Trip (IOI23_longesttrip) C++17
40 / 100
933 ms 1444 KB
#include "longesttrip.h"

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

std::vector<int> longest_trip(int N, int D) {
    vector<vector<int>> g(N);
    if (D == 3) {
        vector<int> v;
        for (int i=0;i<N;i++) {
            v.push_back(i);
        }
        return v;
    }

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

    int tries = 17;
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    for (int i=0;i<N;i++) {
        shuffle(g[i].begin(), g[i].end(), rng);
    }

    vector<int> lng;
    for (int i=0;i<tries;i++) {
        vector<int> tmp;
        vector<bool> vis(N, false);
        function<void(int)> dfs=[&](int node) {
            vis[node] = true;
            tmp.push_back(node);
            if (uniform_int_distribution<int>(0, 7)(rng) == 0) shuffle(g[node].begin(), g[node].end(), rng);

            for (int x:g[node]) {
                if (!vis[x]) {
                    dfs(x);
                    break;
                }
            }
        };

        dfs(uniform_int_distribution<int>(0, N-1)(rng));

        if (lng.size() < tmp.size()) {
            lng = tmp;
        }

        if (lng.size() == N) return lng;
    }

    return lng;
}

Compilation message

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:54:24: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   54 |         if (lng.size() == N) return lng;
      |             ~~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 220 ms 732 KB Output is correct
# Verdict Execution time Memory 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
# Verdict Execution time Memory Grader output
1 Correct 9 ms 344 KB Output is correct
2 Correct 21 ms 596 KB Output is correct
3 Correct 141 ms 440 KB Output is correct
4 Correct 403 ms 604 KB Output is correct
5 Correct 839 ms 1004 KB Output is correct
6 Correct 11 ms 344 KB Output is correct
7 Correct 22 ms 344 KB Output is correct
8 Correct 173 ms 592 KB Output is correct
9 Correct 323 ms 700 KB Output is correct
10 Correct 885 ms 956 KB Output is correct
11 Correct 879 ms 1052 KB Output is correct
12 Correct 858 ms 748 KB Output is correct
13 Correct 820 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 344 KB Output is correct
2 Correct 23 ms 344 KB Output is correct
3 Correct 144 ms 600 KB Output is correct
4 Correct 438 ms 600 KB Output is correct
5 Correct 813 ms 996 KB Output is correct
6 Correct 12 ms 344 KB Output is correct
7 Correct 29 ms 344 KB Output is correct
8 Correct 148 ms 452 KB Output is correct
9 Correct 299 ms 504 KB Output is correct
10 Correct 913 ms 1136 KB Output is correct
11 Correct 746 ms 784 KB Output is correct
12 Correct 745 ms 784 KB Output is correct
13 Correct 897 ms 952 KB Output is correct
14 Correct 13 ms 344 KB Output is correct
15 Correct 14 ms 344 KB Output is correct
16 Correct 39 ms 344 KB Output is correct
17 Correct 102 ms 340 KB Output is correct
18 Correct 164 ms 436 KB Output is correct
19 Correct 336 ms 752 KB Output is correct
20 Correct 336 ms 704 KB Output is correct
21 Correct 836 ms 1444 KB Output is correct
22 Correct 873 ms 888 KB Output is correct
23 Correct 913 ms 1380 KB Output is correct
24 Correct 858 ms 948 KB Output is correct
25 Correct 13 ms 344 KB Output is correct
26 Correct 14 ms 344 KB Output is correct
27 Correct 29 ms 344 KB Output is correct
28 Correct 29 ms 344 KB Output is correct
29 Correct 21 ms 344 KB Output is correct
30 Correct 210 ms 448 KB Output is correct
31 Correct 235 ms 460 KB Output is correct
32 Correct 201 ms 448 KB Output is correct
33 Correct 312 ms 344 KB Output is correct
34 Correct 331 ms 448 KB Output is correct
35 Correct 291 ms 496 KB Output is correct
36 Correct 886 ms 956 KB Output is correct
37 Correct 862 ms 1224 KB Output is correct
38 Correct 883 ms 1116 KB Output is correct
39 Correct 933 ms 964 KB Output is correct
40 Correct 842 ms 848 KB Output is correct
41 Correct 836 ms 1120 KB Output is correct
42 Correct 830 ms 852 KB Output is correct
43 Correct 828 ms 1228 KB Output is correct
44 Correct 847 ms 1012 KB Output is correct
45 Correct 9 ms 344 KB Output is correct
46 Correct 12 ms 344 KB Output is correct
47 Correct 18 ms 344 KB Output is correct
48 Correct 27 ms 344 KB Output is correct
49 Correct 22 ms 344 KB Output is correct
50 Correct 183 ms 344 KB Output is correct
51 Correct 217 ms 344 KB Output is correct
52 Correct 193 ms 436 KB Output is correct
53 Correct 329 ms 680 KB Output is correct
54 Correct 306 ms 616 KB Output is correct
55 Correct 299 ms 848 KB Output is correct
56 Correct 898 ms 848 KB Output is correct
57 Correct 860 ms 872 KB Output is correct
58 Correct 834 ms 932 KB Output is correct
59 Correct 824 ms 936 KB Output is correct
60 Correct 817 ms 988 KB Output is correct
61 Correct 815 ms 836 KB Output is correct
62 Correct 799 ms 752 KB Output is correct
63 Correct 859 ms 1056 KB Output is correct
64 Correct 852 ms 1260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 344 KB Output is correct
2 Correct 27 ms 344 KB Output is correct
3 Partially correct 152 ms 436 KB Output is partially correct
4 Partially correct 425 ms 496 KB Output is partially correct
5 Partially correct 865 ms 1384 KB Output is partially correct
6 Correct 10 ms 344 KB Output is correct
7 Correct 19 ms 344 KB Output is correct
8 Partially correct 158 ms 344 KB Output is partially correct
9 Partially correct 306 ms 848 KB Output is partially correct
10 Partially correct 819 ms 1008 KB Output is partially correct
11 Partially correct 817 ms 984 KB Output is partially correct
12 Partially correct 886 ms 1128 KB Output is partially correct
13 Partially correct 828 ms 740 KB Output is partially correct
14 Correct 11 ms 344 KB Output is correct
15 Correct 15 ms 344 KB Output is correct
16 Incorrect 30 ms 344 KB Incorrect
17 Halted 0 ms 0 KB -