답안 #1065270

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1065270 2024-08-19T05:36:20 Z LittleOrange 가장 긴 여행 (IOI23_longesttrip) C++17
40 / 100
909 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 = 500000/max(n,10);
    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;
      |            ~~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 198 ms 684 KB Incorrect
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 344 KB Output is correct
2 Correct 2 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 344 KB Output is correct
2 Correct 22 ms 344 KB Output is correct
3 Correct 132 ms 344 KB Output is correct
4 Correct 399 ms 484 KB Output is correct
5 Correct 824 ms 684 KB Output is correct
6 Correct 13 ms 596 KB Output is correct
7 Correct 34 ms 344 KB Output is correct
8 Correct 141 ms 344 KB Output is correct
9 Correct 291 ms 344 KB Output is correct
10 Correct 819 ms 688 KB Output is correct
11 Correct 874 ms 684 KB Output is correct
12 Correct 798 ms 680 KB Output is correct
13 Correct 866 ms 684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 344 KB Output is correct
2 Correct 23 ms 344 KB Output is correct
3 Correct 137 ms 344 KB Output is correct
4 Correct 429 ms 484 KB Output is correct
5 Correct 803 ms 688 KB Output is correct
6 Correct 8 ms 344 KB Output is correct
7 Correct 15 ms 344 KB Output is correct
8 Correct 151 ms 344 KB Output is correct
9 Correct 331 ms 344 KB Output is correct
10 Correct 842 ms 688 KB Output is correct
11 Correct 821 ms 684 KB Output is correct
12 Correct 852 ms 684 KB Output is correct
13 Correct 833 ms 688 KB Output is correct
14 Correct 12 ms 344 KB Output is correct
15 Correct 9 ms 344 KB Output is correct
16 Correct 96 ms 344 KB Output is correct
17 Correct 276 ms 344 KB Output is correct
18 Correct 254 ms 348 KB Output is correct
19 Correct 358 ms 592 KB Output is correct
20 Correct 329 ms 592 KB Output is correct
21 Correct 834 ms 700 KB Output is correct
22 Correct 908 ms 696 KB Output is correct
23 Correct 815 ms 692 KB Output is correct
24 Correct 862 ms 692 KB Output is correct
25 Correct 11 ms 344 KB Output is correct
26 Correct 9 ms 344 KB Output is correct
27 Correct 33 ms 344 KB Output is correct
28 Correct 19 ms 344 KB Output is correct
29 Correct 22 ms 344 KB Output is correct
30 Correct 204 ms 344 KB Output is correct
31 Correct 228 ms 344 KB Output is correct
32 Correct 192 ms 344 KB Output is correct
33 Correct 320 ms 344 KB Output is correct
34 Correct 332 ms 344 KB Output is correct
35 Correct 290 ms 344 KB Output is correct
36 Correct 816 ms 600 KB Output is correct
37 Correct 821 ms 600 KB Output is correct
38 Correct 855 ms 600 KB Output is correct
39 Correct 825 ms 600 KB Output is correct
40 Correct 826 ms 600 KB Output is correct
41 Correct 780 ms 600 KB Output is correct
42 Correct 847 ms 600 KB Output is correct
43 Correct 873 ms 600 KB Output is correct
44 Correct 859 ms 600 KB Output is correct
45 Correct 8 ms 344 KB Output is correct
46 Correct 10 ms 340 KB Output is correct
47 Correct 31 ms 344 KB Output is correct
48 Correct 23 ms 344 KB Output is correct
49 Correct 24 ms 344 KB Output is correct
50 Correct 223 ms 344 KB Output is correct
51 Correct 303 ms 344 KB Output is correct
52 Correct 321 ms 344 KB Output is correct
53 Correct 353 ms 344 KB Output is correct
54 Correct 355 ms 344 KB Output is correct
55 Correct 351 ms 344 KB Output is correct
56 Correct 877 ms 688 KB Output is correct
57 Correct 864 ms 848 KB Output is correct
58 Correct 884 ms 684 KB Output is correct
59 Correct 885 ms 688 KB Output is correct
60 Correct 877 ms 688 KB Output is correct
61 Correct 902 ms 600 KB Output is correct
62 Correct 899 ms 688 KB Output is correct
63 Correct 872 ms 688 KB Output is correct
64 Correct 909 ms 684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 344 KB Output is correct
2 Correct 24 ms 344 KB Output is correct
3 Partially correct 146 ms 344 KB Output is partially correct
4 Partially correct 409 ms 488 KB Output is partially correct
5 Partially correct 797 ms 680 KB Output is partially correct
6 Correct 10 ms 344 KB Output is correct
7 Correct 23 ms 344 KB Output is correct
8 Partially correct 170 ms 344 KB Output is partially correct
9 Partially correct 333 ms 344 KB Output is partially correct
10 Partially correct 862 ms 684 KB Output is partially correct
11 Partially correct 841 ms 684 KB Output is partially correct
12 Partially correct 844 ms 684 KB Output is partially correct
13 Partially correct 808 ms 692 KB Output is partially correct
14 Correct 8 ms 344 KB Output is correct
15 Correct 10 ms 344 KB Output is correct
16 Correct 92 ms 344 KB Output is correct
17 Incorrect 12 ms 344 KB Incorrect
18 Halted 0 ms 0 KB -