Submission #1080923

# Submission time Handle Problem Language Result Execution time Memory
1080923 2024-08-29T16:01:47 Z asdasdqwer Longest Trip (IOI23_longesttrip) C++17
40 / 100
929 ms 1304 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 ((D == 2 && lng.size() == N) || (D == 1 && lng.size() >= (N/2+1))) return lng;
    }

    return lng;
}

Compilation message

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:54:35: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   54 |         if ((D == 2 && lng.size() == N) || (D == 1 && lng.size() >= (N/2+1))) return lng;
      |                        ~~~~~~~~~~~^~~~
longesttrip.cpp:54:66: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   54 |         if ((D == 2 && lng.size() == N) || (D == 1 && lng.size() >= (N/2+1))) return lng;
      |                                                       ~~~~~~~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 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
# Verdict Execution time Memory Grader output
1 Correct 9 ms 344 KB Output is correct
2 Correct 32 ms 344 KB Output is correct
3 Correct 154 ms 344 KB Output is correct
4 Correct 417 ms 504 KB Output is correct
5 Correct 860 ms 1176 KB Output is correct
6 Correct 9 ms 344 KB Output is correct
7 Correct 30 ms 344 KB Output is correct
8 Correct 126 ms 464 KB Output is correct
9 Correct 298 ms 504 KB Output is correct
10 Correct 773 ms 860 KB Output is correct
11 Correct 840 ms 1088 KB Output is correct
12 Correct 857 ms 780 KB Output is correct
13 Correct 838 ms 968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 344 KB Output is correct
2 Correct 28 ms 344 KB Output is correct
3 Correct 137 ms 600 KB Output is correct
4 Correct 466 ms 724 KB Output is correct
5 Correct 829 ms 1304 KB Output is correct
6 Correct 13 ms 344 KB Output is correct
7 Correct 28 ms 344 KB Output is correct
8 Correct 155 ms 452 KB Output is correct
9 Correct 339 ms 896 KB Output is correct
10 Correct 747 ms 792 KB Output is correct
11 Correct 856 ms 1052 KB Output is correct
12 Correct 738 ms 864 KB Output is correct
13 Correct 785 ms 820 KB Output is correct
14 Correct 12 ms 344 KB Output is correct
15 Correct 11 ms 344 KB Output is correct
16 Correct 51 ms 344 KB Output is correct
17 Correct 82 ms 344 KB Output is correct
18 Correct 143 ms 344 KB Output is correct
19 Correct 320 ms 508 KB Output is correct
20 Correct 317 ms 724 KB Output is correct
21 Correct 872 ms 1004 KB Output is correct
22 Correct 802 ms 1036 KB Output is correct
23 Correct 800 ms 1280 KB Output is correct
24 Correct 728 ms 848 KB Output is correct
25 Correct 11 ms 344 KB Output is correct
26 Correct 14 ms 344 KB Output is correct
27 Correct 22 ms 344 KB Output is correct
28 Correct 27 ms 344 KB Output is correct
29 Correct 32 ms 344 KB Output is correct
30 Correct 173 ms 612 KB Output is correct
31 Correct 179 ms 452 KB Output is correct
32 Correct 171 ms 344 KB Output is correct
33 Correct 277 ms 476 KB Output is correct
34 Correct 287 ms 992 KB Output is correct
35 Correct 273 ms 724 KB Output is correct
36 Correct 695 ms 1008 KB Output is correct
37 Correct 713 ms 992 KB Output is correct
38 Correct 798 ms 924 KB Output is correct
39 Correct 808 ms 1052 KB Output is correct
40 Correct 817 ms 980 KB Output is correct
41 Correct 856 ms 732 KB Output is correct
42 Correct 771 ms 988 KB Output is correct
43 Correct 842 ms 812 KB Output is correct
44 Correct 844 ms 800 KB Output is correct
45 Correct 12 ms 344 KB Output is correct
46 Correct 11 ms 344 KB Output is correct
47 Correct 31 ms 416 KB Output is correct
48 Correct 25 ms 344 KB Output is correct
49 Correct 31 ms 344 KB Output is correct
50 Correct 174 ms 460 KB Output is correct
51 Correct 177 ms 696 KB Output is correct
52 Correct 178 ms 456 KB Output is correct
53 Correct 293 ms 720 KB Output is correct
54 Correct 311 ms 480 KB Output is correct
55 Correct 334 ms 724 KB Output is correct
56 Correct 829 ms 724 KB Output is correct
57 Correct 785 ms 1124 KB Output is correct
58 Correct 841 ms 848 KB Output is correct
59 Correct 838 ms 924 KB Output is correct
60 Correct 887 ms 788 KB Output is correct
61 Correct 844 ms 784 KB Output is correct
62 Correct 929 ms 864 KB Output is correct
63 Correct 828 ms 944 KB Output is correct
64 Correct 888 ms 1068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 344 KB Output is correct
2 Correct 29 ms 344 KB Output is correct
3 Partially correct 133 ms 460 KB Output is partially correct
4 Partially correct 415 ms 492 KB Output is partially correct
5 Partially correct 859 ms 1128 KB Output is partially correct
6 Incorrect 0 ms 344 KB Incorrect
7 Halted 0 ms 0 KB -