Submission #1065199

# Submission time Handle Problem Language Result Execution time Memory
1065199 2024-08-19T03:08:09 Z LittleOrange Longest Trip (IOI23_longesttrip) C++17
5 / 100
1000 ms 348 KB
#include "longesttrip.h"

#include <vector>
#include<bits/stdc++.h>
using namespace std;
using ll = int;

std::vector<int> longest_trip(int N, int D)
{
    mt19937_64 mt(random_device{}());
    ll t0 = time(0);
    ll n = N;
    if (D==3){
        vector<ll> r(n);
        iota(r.begin(),r.end(),0);
        return r;
    }
    vector<vector<ll>> a(n,vector<ll>(n,0));
    for(ll i = 0;i<n;i++){
        for(ll j = i+1;j<n;j++){
            a[i][j] = a[j][i] = are_connected({i},{j});
        }
    }
    vector<ll> vis(n,0);
    vector<ll> ret;
    vector<ll> ord(n);
    iota(ord.begin(),ord.end(),0);
    auto it = ord.begin();
    vector<ll> cur;
    function<void(ll)> dfs;
    dfs = [&](ll i){
        cur.push_back(i);
        vis[i] = 1;
        for(;it!=ord.end();it++){
            ll j = *it;
            if(a[i][j]&&!vis[j]){
                dfs(j);
                return;
            }
        }
    };
    while(time(0)<t0+1){
        shuffle(ord.begin(),ord.end(),mt);
        it = ord.begin();
        dfs(ord[0]);
        if(cur.size()>ret.size()) ret = cur;
        cur.clear();
        for(ll i = 0;i<n;i++) vis[i] = 0;
    }
    return ret;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 1887 ms 344 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 348 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 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3044 ms 344 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3098 ms 344 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3060 ms 344 KB Time limit exceeded
2 Halted 0 ms 0 KB -