답안 #1042881

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1042881 2024-08-03T13:58:26 Z kwongweng 가장 긴 여행 (IOI23_longesttrip) C++17
60 / 100
282 ms 600 KB
#include "longesttrip.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long double ld;
typedef vector<vector<ll>> vll;
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define ROF(i, a, b) for(int i = a; i >= b; i--)
#define pb push_back
#define ms memset
#define fi first
#define se second

vi longest_trip(int N, int D)
{
    vector<vi> CC;
    FOR(i,0,N) CC.pb({i});
    while (CC.size() > 2){
        int sz = CC.size(), s0 = CC[0].size(), s1 = CC[1].size(), sn = CC[sz-1].size();
        if (are_connected({CC[sz-1][0]}, {CC[0][s0-1]})){
            FOR(i,0,sn){
                CC[0].pb(CC[sz-1][i]);
            }
            CC.pop_back(); continue;
        }
        if (are_connected({CC[sz-1][0]}, {CC[1][s1-1]})){
            FOR(i,0,sn){
                CC[1].pb(CC[sz-1][i]);
            }
            CC.pop_back(); continue;
        }
        ROF(i,s1-1,0){
            CC[0].pb(CC[1][i]);
        }
        FOR(i,1,sz-1){
            CC[i]=CC[i+1];
        }
        CC.pop_back();
    }
    int s0 = CC[0].size(), s1 = CC[1].size();
    if (are_connected(CC[0], CC[1])){
        if (are_connected({CC[0][0]}, {CC[1][0]})){
            reverse(CC[0].begin(), CC[0].end());
            FOR(i,0,s1) CC[0].pb(CC[1][i]);
            return CC[0];
        }
        if (are_connected({CC[0][0]}, {CC[1][s1-1]})){
            reverse(CC[0].begin(), CC[0].end());
            reverse(CC[1].begin(), CC[1].end());
            FOR(i,0,s1) CC[0].pb(CC[1][i]);
            return CC[0];
        }
        if (are_connected({CC[0][s0-1]}, {CC[1][0]})){
            FOR(i,0,s1) CC[0].pb(CC[1][i]);
            return CC[0];
        }
        if (are_connected({CC[0][s0-1]}, {CC[1][s1-1]})){
            reverse(CC[1].begin(), CC[1].end());
            FOR(i,0,s1) CC[0].pb(CC[1][i]);
            return CC[0];
        }
        FOR(i,0,s0){
            FOR(j,0,s1){
                if (are_connected({CC[0][i]},{CC[1][j]})){
                    vi ans;
                    FOR(k,i+1,i+s0+1) ans.pb(CC[0][k%s0]);
                    FOR(k,j,j+s1) ans.pb(CC[1][k%s1]);
                    return ans;
                }
            }
        }
        int l = 0, r = s0;
        while (r-l>1){
            int mid = (l+r)/2;
            vi A; FOR(i,0,mid) A.pb(CC[0][i]);
            if (are_connected(A, CC[1])){
                r = mid;
            }else{
                l = mid;
            }
        }
        int a = r; l=0; r=s1;
        while (r-l>1){
            int mid = (l+r)/2;
            vi A; FOR(i,0,mid) A.pb(CC[1][i]);
            if (are_connected({a}, A)){
                r=mid;
            }else{
                l=mid;
            }
        }
        vi ans;
        FOR(i,a+1,a+s0+1) ans.pb(CC[0][i%s0]);
        FOR(i,r,r+s1) ans.pb(CC[1][i%s1]);
        return ans;
    }
    if (CC[0].size()>CC[1].size()) return CC[0];
    return CC[1];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 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 6 ms 344 KB Output is correct
4 Correct 5 ms 348 KB Output is correct
5 Correct 5 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 344 KB Output is correct
2 Correct 5 ms 344 KB Output is correct
3 Correct 3 ms 344 KB Output is correct
4 Correct 5 ms 344 KB Output is correct
5 Correct 3 ms 340 KB Output is correct
6 Correct 7 ms 344 KB Output is correct
7 Correct 4 ms 344 KB Output is correct
8 Correct 4 ms 344 KB Output is correct
9 Correct 4 ms 344 KB Output is correct
10 Correct 6 ms 600 KB Output is correct
11 Correct 5 ms 344 KB Output is correct
12 Correct 6 ms 452 KB Output is correct
13 Correct 6 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 6 ms 344 KB Output is correct
3 Correct 7 ms 344 KB Output is correct
4 Correct 5 ms 344 KB Output is correct
5 Correct 4 ms 452 KB Output is correct
6 Correct 7 ms 344 KB Output is correct
7 Correct 7 ms 344 KB Output is correct
8 Correct 5 ms 344 KB Output is correct
9 Correct 4 ms 344 KB Output is correct
10 Correct 6 ms 452 KB Output is correct
11 Correct 5 ms 344 KB Output is correct
12 Correct 7 ms 344 KB Output is correct
13 Correct 5 ms 344 KB Output is correct
14 Correct 5 ms 344 KB Output is correct
15 Correct 7 ms 344 KB Output is correct
16 Correct 7 ms 344 KB Output is correct
17 Correct 6 ms 344 KB Output is correct
18 Correct 6 ms 344 KB Output is correct
19 Correct 5 ms 344 KB Output is correct
20 Correct 8 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 8 ms 344 KB Output is correct
24 Correct 5 ms 344 KB Output is correct
25 Correct 6 ms 344 KB Output is correct
26 Correct 5 ms 344 KB Output is correct
27 Correct 5 ms 344 KB Output is correct
28 Correct 6 ms 344 KB Output is correct
29 Correct 4 ms 344 KB Output is correct
30 Correct 6 ms 344 KB Output is correct
31 Correct 5 ms 344 KB Output is correct
32 Correct 6 ms 344 KB Output is correct
33 Correct 7 ms 344 KB Output is correct
34 Correct 6 ms 344 KB Output is correct
35 Correct 5 ms 344 KB Output is correct
36 Correct 6 ms 344 KB Output is correct
37 Correct 5 ms 344 KB Output is correct
38 Correct 7 ms 344 KB Output is correct
39 Correct 8 ms 344 KB Output is correct
40 Correct 7 ms 344 KB Output is correct
41 Correct 9 ms 428 KB Output is correct
42 Correct 4 ms 344 KB Output is correct
43 Correct 7 ms 344 KB Output is correct
44 Correct 8 ms 452 KB Output is correct
45 Correct 7 ms 344 KB Output is correct
46 Correct 7 ms 344 KB Output is correct
47 Correct 5 ms 344 KB Output is correct
48 Correct 7 ms 344 KB Output is correct
49 Correct 7 ms 344 KB Output is correct
50 Correct 10 ms 348 KB Output is correct
51 Correct 36 ms 600 KB Output is correct
52 Correct 49 ms 436 KB Output is correct
53 Correct 6 ms 344 KB Output is correct
54 Correct 9 ms 344 KB Output is correct
55 Correct 15 ms 344 KB Output is correct
56 Correct 7 ms 344 KB Output is correct
57 Correct 20 ms 348 KB Output is correct
58 Correct 75 ms 348 KB Output is correct
59 Correct 79 ms 344 KB Output is correct
60 Correct 87 ms 344 KB Output is correct
61 Correct 227 ms 436 KB Output is correct
62 Correct 84 ms 344 KB Output is correct
63 Correct 93 ms 344 KB Output is correct
64 Correct 137 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 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 5 ms 344 KB Output is correct
6 Correct 7 ms 344 KB Output is correct
7 Correct 5 ms 344 KB Output is correct
8 Correct 4 ms 344 KB Output is correct
9 Correct 4 ms 448 KB Output is correct
10 Correct 5 ms 344 KB Output is correct
11 Correct 3 ms 344 KB Output is correct
12 Correct 4 ms 344 KB Output is correct
13 Correct 5 ms 344 KB Output is correct
14 Correct 5 ms 344 KB Output is correct
15 Correct 7 ms 344 KB Output is correct
16 Correct 7 ms 344 KB Output is correct
17 Correct 7 ms 340 KB Output is correct
18 Correct 8 ms 344 KB Output is correct
19 Correct 6 ms 344 KB Output is correct
20 Correct 5 ms 344 KB Output is correct
21 Correct 4 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 6 ms 344 KB Output is correct
25 Correct 6 ms 344 KB Output is correct
26 Correct 8 ms 344 KB Output is correct
27 Correct 4 ms 344 KB Output is correct
28 Correct 6 ms 344 KB Output is correct
29 Correct 6 ms 344 KB Output is correct
30 Correct 6 ms 344 KB Output is correct
31 Correct 8 ms 344 KB Output is correct
32 Correct 8 ms 344 KB Output is correct
33 Correct 10 ms 344 KB Output is correct
34 Correct 9 ms 344 KB Output is correct
35 Correct 7 ms 344 KB Output is correct
36 Correct 7 ms 344 KB Output is correct
37 Correct 6 ms 344 KB Output is correct
38 Partially correct 25 ms 344 KB Output is partially correct
39 Partially correct 44 ms 344 KB Output is partially correct
40 Correct 7 ms 344 KB Output is correct
41 Correct 10 ms 344 KB Output is correct
42 Partially correct 10 ms 344 KB Output is partially correct
43 Correct 4 ms 344 KB Output is correct
44 Correct 5 ms 344 KB Output is correct
45 Correct 6 ms 344 KB Output is correct
46 Correct 5 ms 344 KB Output is correct
47 Partially correct 6 ms 448 KB Output is partially correct
48 Correct 5 ms 452 KB Output is correct
49 Correct 5 ms 344 KB Output is correct
50 Correct 6 ms 452 KB Output is correct
51 Partially correct 6 ms 448 KB Output is partially correct
52 Correct 9 ms 344 KB Output is correct
53 Correct 7 ms 600 KB Output is correct
54 Correct 7 ms 344 KB Output is correct
55 Correct 5 ms 344 KB Output is correct
56 Correct 6 ms 344 KB Output is correct
57 Partially correct 5 ms 344 KB Output is partially correct
58 Partially correct 5 ms 344 KB Output is partially correct
59 Partially correct 7 ms 344 KB Output is partially correct
60 Correct 9 ms 460 KB Output is correct
61 Correct 6 ms 344 KB Output is correct
62 Partially correct 9 ms 344 KB Output is partially correct
63 Partially correct 27 ms 440 KB Output is partially correct
64 Partially correct 79 ms 424 KB Output is partially correct
65 Partially correct 88 ms 344 KB Output is partially correct
66 Partially correct 77 ms 600 KB Output is partially correct
67 Partially correct 282 ms 344 KB Output is partially correct
68 Partially correct 61 ms 432 KB Output is partially correct
69 Partially correct 120 ms 432 KB Output is partially correct
70 Partially correct 119 ms 344 KB Output is partially correct
71 Partially correct 24 ms 344 KB Output is partially correct
72 Partially correct 93 ms 448 KB Output is partially correct
73 Partially correct 146 ms 344 KB Output is partially correct
74 Partially correct 176 ms 436 KB Output is partially correct
75 Partially correct 188 ms 344 KB Output is partially correct
76 Partially correct 145 ms 344 KB Output is partially correct
77 Partially correct 20 ms 344 KB Output is partially correct
78 Partially correct 89 ms 344 KB Output is partially correct
79 Partially correct 147 ms 344 KB Output is partially correct
80 Partially correct 198 ms 428 KB Output is partially correct
81 Partially correct 207 ms 592 KB Output is partially correct
82 Partially correct 145 ms 432 KB Output is partially correct