답안 #1078129

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1078129 2024-08-27T13:05:01 Z idas 가장 긴 여행 (IOI23_longesttrip) C++17
40 / 100
362 ms 1956 KB
#include "bits/stdc++.h"
#include "longesttrip.h"

#define FOR(i, begin, end) for(int i=(begin); i<(end); i++)
#define sz(x) ((int)(x).size())
#define pb push_back

using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;

int n, d;
map<pii, bool> mp;

bool con(int a, int b) {
    if(mp.count({a,b})) return mp[{a,b}];
    return mp[{a,b}]=are_connected({a},{b});
}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

std::vector<int> longest_trip(int N, int D) {
    mp.clear();
    n=N; d=D;
    if(d==3) {
        vi ans;
        FOR(i, 0, n) ans.pb(i);
        return ans;
    }
    if(d==2) {
        vi ins;
        FOR(i, 0, n) ins.pb(i);

        shuffle(ins.begin(), ins.end(), rng);

        vi ans;
        int st=0;
        while(sz(ans)<n) {
            ans.clear();
            vector v(n, false);
            ans.pb(ins[st]); v[ins[st]]=true;
            FOR(z, 0, n-1) {
                FOR(j, 0, n) {
                    int i=ins[j];
                    if(v[i]) continue;
                    if(con(ans.back(), i)) {
                        ans.pb(i);
                        v[i]=true;
                        break;
                    }
                }
            }
            st++;
        }

        return ans;
    }

    vi ins;
    FOR(i, 0, n) ins.pb(i);

    shuffle(ins.begin(), ins.end(), rng);

    vi ans;
    int st=0;
    while(sz(ans)<(n+1)/2) {
        ans.clear();
        vector v(n, false);
        ans.pb(ins[st]); v[ins[st]]=true;
        FOR(z, 0, n-1) {
            FOR(j, 0, n) {
                int i=ins[j];
                if(v[i]) continue;
                if(con(ans.back(), i)) {
                    ans.pb(i);
                    v[i]=true;
                    break;
                }
            }
        }
        st++;
    }

    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 2 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 6 ms 344 KB Output is correct
3 Correct 6 ms 344 KB Output is correct
4 Correct 5 ms 344 KB Output is correct
5 Correct 6 ms 344 KB Output is correct
6 Correct 6 ms 344 KB Output is correct
7 Correct 7 ms 440 KB Output is correct
8 Correct 6 ms 344 KB Output is correct
9 Correct 6 ms 344 KB Output is correct
10 Correct 5 ms 344 KB Output is correct
11 Correct 6 ms 344 KB Output is correct
12 Correct 5 ms 344 KB Output is correct
13 Correct 6 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 344 KB Output is correct
2 Correct 5 ms 344 KB Output is correct
3 Correct 4 ms 344 KB Output is correct
4 Correct 5 ms 344 KB Output is correct
5 Correct 5 ms 344 KB Output is correct
6 Correct 6 ms 344 KB Output is correct
7 Correct 5 ms 340 KB Output is correct
8 Correct 8 ms 344 KB Output is correct
9 Correct 5 ms 344 KB Output is correct
10 Correct 6 ms 344 KB Output is correct
11 Correct 6 ms 344 KB Output is correct
12 Correct 5 ms 344 KB Output is correct
13 Correct 5 ms 344 KB Output is correct
14 Correct 7 ms 344 KB Output is correct
15 Correct 10 ms 344 KB Output is correct
16 Correct 6 ms 344 KB Output is correct
17 Correct 7 ms 344 KB Output is correct
18 Correct 7 ms 344 KB Output is correct
19 Correct 6 ms 344 KB Output is correct
20 Correct 7 ms 344 KB Output is correct
21 Correct 6 ms 344 KB Output is correct
22 Correct 6 ms 344 KB Output is correct
23 Correct 6 ms 344 KB Output is correct
24 Correct 7 ms 460 KB Output is correct
25 Correct 8 ms 344 KB Output is correct
26 Correct 4 ms 344 KB Output is correct
27 Correct 8 ms 344 KB Output is correct
28 Correct 8 ms 344 KB Output is correct
29 Correct 11 ms 344 KB Output is correct
30 Correct 7 ms 344 KB Output is correct
31 Correct 38 ms 460 KB Output is correct
32 Correct 59 ms 452 KB Output is correct
33 Correct 7 ms 340 KB Output is correct
34 Correct 14 ms 344 KB Output is correct
35 Correct 23 ms 344 KB Output is correct
36 Correct 11 ms 600 KB Output is correct
37 Correct 42 ms 592 KB Output is correct
38 Correct 220 ms 1160 KB Output is correct
39 Correct 298 ms 1956 KB Output is correct
40 Correct 359 ms 1916 KB Output is correct
41 Correct 236 ms 964 KB Output is correct
42 Correct 241 ms 984 KB Output is correct
43 Correct 324 ms 1608 KB Output is correct
44 Correct 362 ms 1356 KB Output is correct
45 Correct 4 ms 344 KB Output is correct
46 Correct 6 ms 344 KB Output is correct
47 Correct 7 ms 344 KB Output is correct
48 Correct 7 ms 344 KB Output is correct
49 Correct 6 ms 344 KB Output is correct
50 Correct 9 ms 444 KB Output is correct
51 Correct 35 ms 712 KB Output is correct
52 Correct 47 ms 592 KB Output is correct
53 Correct 6 ms 448 KB Output is correct
54 Correct 20 ms 344 KB Output is correct
55 Correct 25 ms 856 KB Output is correct
56 Correct 11 ms 600 KB Output is correct
57 Correct 147 ms 784 KB Output is correct
58 Correct 260 ms 936 KB Output is correct
59 Correct 333 ms 1140 KB Output is correct
60 Correct 249 ms 1408 KB Output is correct
61 Correct 182 ms 1120 KB Output is correct
62 Correct 166 ms 1048 KB Output is correct
63 Correct 282 ms 1104 KB Output is correct
64 Correct 251 ms 1740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 344 KB Output is correct
2 Correct 5 ms 344 KB Output is correct
3 Correct 5 ms 344 KB Output is correct
4 Correct 5 ms 344 KB Output is correct
5 Correct 5 ms 456 KB Output is correct
6 Incorrect 0 ms 344 KB Incorrect
7 Halted 0 ms 0 KB -