Submission #1065271

# Submission time Handle Problem Language Result Execution time Memory
1065271 2024-08-19T05:39:16 Z LittleOrange Longest Trip (IOI23_longesttrip) C++17
40 / 100
891 ms 848 KB
#include "longesttrip.h"

#include <vector>
#include<bits/stdc++.h>
using namespace std;
using ll = int;
struct dsu{
    ll c;
    vector<ll> p;
    dsu(ll N):c(N),p(N,-1){}
    ll g(ll i){
        return p[i]<0?i:p[i] = g(p[i]);
    }
    bool m(ll a, ll b){
        a = g(a),b=g(b);
        if(a==b) return false;
        c--;
        if(p[a]>p[b]) swap(a,b);
        p[a] += p[b];
        p[b] = a;
        return true;
    }
};

std::vector<int> longest_trip(int N, int D)
{
    mt19937_64 mt(random_device{}());
    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));
    dsu d(n);
    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});
            if(a[i][j]) d.m(i,j);
        }
    }
    if (d.c>1){
        ll g = d.g(0);
        for(ll i = 0;i<n;i++){
            ll j = d.g(i);
            if (d.p[j]<d.p[g]) g = j;
        }
        vector<ll> v;
        for(ll i = 0;i<n;i++){
            if (d.g(i)==g) v.push_back(i);
        }
        return v;
    }
    vector<ll> ret;
    vector<ll> ord(n);
    iota(ord.begin(),ord.end(),0);
    vector<ll> cur;
    cur.reserve(n);
    ll cnt = 50;
    while(cnt--){
        shuffle(ord.begin(),ord.end(),mt);
        cur.push_back(ord[0]);
        for(ll i : ord){
            if (a[cur.back()][i]) cur.push_back(i);
        }
        if(cur.size()>ret.size()) ret = cur;
        cur.clear();
        if(ret.size()==n) break;
    }
    return ret;
}

Compilation message

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:68:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'int'} [-Wsign-compare]
   68 |         if(ret.size()==n) break;
      |            ~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 178 ms 688 KB Incorrect
3 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 1 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 10 ms 344 KB Output is correct
2 Correct 23 ms 344 KB Output is correct
3 Correct 158 ms 344 KB Output is correct
4 Correct 410 ms 344 KB Output is correct
5 Correct 815 ms 684 KB Output is correct
6 Correct 8 ms 340 KB Output is correct
7 Correct 23 ms 344 KB Output is correct
8 Correct 143 ms 344 KB Output is correct
9 Correct 303 ms 344 KB Output is correct
10 Correct 855 ms 848 KB Output is correct
11 Correct 780 ms 688 KB Output is correct
12 Correct 871 ms 684 KB Output is correct
13 Correct 831 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 344 KB Output is correct
2 Correct 31 ms 340 KB Output is correct
3 Correct 138 ms 344 KB Output is correct
4 Correct 414 ms 592 KB Output is correct
5 Correct 842 ms 704 KB Output is correct
6 Correct 9 ms 344 KB Output is correct
7 Correct 25 ms 344 KB Output is correct
8 Correct 170 ms 344 KB Output is correct
9 Correct 333 ms 464 KB Output is correct
10 Correct 824 ms 684 KB Output is correct
11 Correct 808 ms 684 KB Output is correct
12 Correct 839 ms 848 KB Output is correct
13 Correct 844 ms 684 KB Output is correct
14 Correct 9 ms 344 KB Output is correct
15 Correct 11 ms 344 KB Output is correct
16 Correct 41 ms 344 KB Output is correct
17 Correct 100 ms 600 KB Output is correct
18 Correct 135 ms 344 KB Output is correct
19 Correct 324 ms 592 KB Output is correct
20 Correct 295 ms 592 KB Output is correct
21 Correct 827 ms 688 KB Output is correct
22 Correct 877 ms 692 KB Output is correct
23 Correct 816 ms 692 KB Output is correct
24 Correct 818 ms 688 KB Output is correct
25 Correct 13 ms 344 KB Output is correct
26 Correct 9 ms 344 KB Output is correct
27 Correct 17 ms 344 KB Output is correct
28 Correct 21 ms 344 KB Output is correct
29 Correct 24 ms 344 KB Output is correct
30 Correct 225 ms 344 KB Output is correct
31 Correct 192 ms 344 KB Output is correct
32 Correct 186 ms 344 KB Output is correct
33 Correct 286 ms 344 KB Output is correct
34 Correct 316 ms 344 KB Output is correct
35 Correct 329 ms 344 KB Output is correct
36 Correct 853 ms 600 KB Output is correct
37 Correct 835 ms 600 KB Output is correct
38 Correct 835 ms 600 KB Output is correct
39 Correct 815 ms 600 KB Output is correct
40 Correct 845 ms 600 KB Output is correct
41 Correct 830 ms 600 KB Output is correct
42 Correct 840 ms 600 KB Output is correct
43 Correct 805 ms 600 KB Output is correct
44 Correct 739 ms 600 KB Output is correct
45 Correct 11 ms 344 KB Output is correct
46 Correct 13 ms 344 KB Output is correct
47 Correct 25 ms 344 KB Output is correct
48 Correct 34 ms 344 KB Output is correct
49 Correct 33 ms 344 KB Output is correct
50 Correct 183 ms 344 KB Output is correct
51 Correct 160 ms 344 KB Output is correct
52 Correct 165 ms 344 KB Output is correct
53 Correct 248 ms 344 KB Output is correct
54 Correct 280 ms 344 KB Output is correct
55 Correct 294 ms 344 KB Output is correct
56 Correct 891 ms 684 KB Output is correct
57 Correct 793 ms 692 KB Output is correct
58 Correct 818 ms 600 KB Output is correct
59 Correct 834 ms 684 KB Output is correct
60 Correct 851 ms 692 KB Output is correct
61 Correct 865 ms 684 KB Output is correct
62 Correct 768 ms 684 KB Output is correct
63 Correct 808 ms 692 KB Output is correct
64 Correct 870 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 344 KB Output is correct
2 Correct 21 ms 344 KB Output is correct
3 Partially correct 154 ms 344 KB Output is partially correct
4 Partially correct 409 ms 484 KB Output is partially correct
5 Partially correct 799 ms 684 KB Output is partially correct
6 Correct 11 ms 344 KB Output is correct
7 Correct 29 ms 344 KB Output is correct
8 Partially correct 129 ms 344 KB Output is partially correct
9 Partially correct 325 ms 344 KB Output is partially correct
10 Partially correct 846 ms 848 KB Output is partially correct
11 Partially correct 819 ms 688 KB Output is partially correct
12 Partially correct 839 ms 688 KB Output is partially correct
13 Partially correct 816 ms 848 KB Output is partially correct
14 Correct 11 ms 344 KB Output is correct
15 Incorrect 5 ms 344 KB Incorrect
16 Halted 0 ms 0 KB -