Submission #848857

# Submission time Handle Problem Language Result Execution time Memory
848857 2023-09-13T15:59:14 Z d4xn Longest Trip (IOI23_longesttrip) C++17
5 / 100
55 ms 1104 KB
#include "longesttrip.h"
#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()

const int N = 256, T = 1e6;

mt19937 rng(time(nullptr) + (uint64_t) new char);

int cnt;
vector<int> adj[N], ans, curr;
bitset<N> vis;

void dfs(int u) {
    vis[u] = 1;
    curr.push_back(u);
    
    if (curr.size() > ans.size()) ans = curr;

    cnt++;
    if (cnt > T) return;

    for (int& v : adj[u]) {
        if (vis[v]) continue;
        dfs(v);
        if (cnt > T) return;
    }
    
    vis[u] = 1;
    curr.pop_back();
}

vector<int> longest_trip(int N, int D)
{
    if (D == 3) {
        ans.resize(N);
        for (int i = 0; i < N; i++) ans[i] = i;
        return ans;
    }
    else {
        for (int i = 0; i < N; i++) {
            for (int j = i+1; j < N; j++) {
                if (are_connected({i}, {j})) {
                    adj[i].push_back(j);
                    adj[j].push_back(i);
                }
            }
        }

        for (int i = 0; i < 100; i++) {
            cnt = 0;
            vis.reset();
            curr.clear();
            dfs(rng() % N);
        }
        return ans;
    }
}
# 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 2 ms 344 KB Output is correct
2 Correct 2 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 46 ms 856 KB Output is correct
2 Incorrect 55 ms 600 KB Incorrect
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 34 ms 1104 KB Output is correct
2 Incorrect 54 ms 940 KB Incorrect
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 34 ms 848 KB Output is correct
2 Incorrect 55 ms 600 KB Incorrect
3 Halted 0 ms 0 KB -