Submission #1080878

# Submission time Handle Problem Language Result Execution time Memory
1080878 2024-08-29T15:35:23 Z asdasdqwer Longest Trip (IOI23_longesttrip) C++17
0 / 100
1000 ms 988 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);
    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 = 100;
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    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);

            vector<int> suf;
            for (int i=0;i<g[node].size();i++)suf.push_back(i);
            shuffle(suf.begin(), suf.end(), rng);

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

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

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

    return lng;
}

Compilation message

longesttrip.cpp: In lambda function:
longesttrip.cpp:28:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |             for (int i=0;i<g[node].size();i++)suf.push_back(i);
      |                          ~^~~~~~~~~~~~~~~
# 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 20 ms 344 KB Output is correct
2 Correct 38 ms 344 KB Output is correct
3 Incorrect 37 ms 344 KB Incorrect
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 344 KB Output is correct
2 Correct 39 ms 344 KB Output is correct
3 Incorrect 25 ms 344 KB Incorrect
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 344 KB Output is correct
2 Correct 37 ms 596 KB Output is correct
3 Correct 229 ms 448 KB Output is correct
4 Correct 557 ms 732 KB Output is correct
5 Execution timed out 1072 ms 988 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 344 KB Output is correct
2 Correct 45 ms 344 KB Output is correct
3 Incorrect 11 ms 600 KB Incorrect
4 Halted 0 ms 0 KB -