답안 #840053

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
840053 2023-08-31T03:20:32 Z angelo_torres 가장 긴 여행 (IOI23_longesttrip) C++17
25 / 100
990 ms 276 KB
#include "longesttrip.h"
#define sz(v) (int) v.size()
#define ff first
#define ss second

using namespace std;
typedef pair<int,int> ii;

vector<int> longest_trip(int N, int D)
{
    vector<vector<bool>> A(N);
    for(int i = 0; i < N; ++i) A[i].resize(N);
    for(int i = 0; i < N; ++i){
        for(int j = 0; j < i; ++j){
            A[i][j] = are_connected({i},{j});
            A[j][i] = A[i][j];
        }
    }
    vector<int> G(N);
    for(int i = 0; i < N; ++i){
        for(int j = 0; j < N; ++j) if(A[i][j]) G[i]++;
    }
    int x = 0;
    for(int i = 1; i < N; ++i){
        if(G[i] < G[x]) x = i;
    }
    vector<int> ans;
    if(G[x] <= (N/2)-1){
        for(int i = 0; i < N; ++i){
            if((i == x) || A[x][i]) continue;
            ans.push_back(i);
        }
        return ans;
    }
    // G[x] >= (N/2) -> G[i] >= (N/2) for all 0 <= i < N
    vector<bool> T(N,false);
    ans = {0};
    T[0] = 1;
    int last = 0;
    for(int i = 1; i < (N+1)/2; ++i){
        for(int j = 0; j < N; ++j){
            if(T[j] || !A[last][j] || (j == last)) continue;
            // j is not in ans, j is adjacent to last, j is not last
            ans.push_back(j); 
            last = j;
            T[j] = 1;
            break;
        }
    }
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 208 KB Incorrect
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 208 KB Incorrect
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 208 KB Incorrect
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 208 KB Output is correct
2 Correct 39 ms 208 KB Output is correct
3 Correct 188 ms 208 KB Output is correct
4 Correct 463 ms 272 KB Output is correct
5 Correct 769 ms 208 KB Output is correct
6 Correct 12 ms 208 KB Output is correct
7 Correct 35 ms 208 KB Output is correct
8 Correct 187 ms 208 KB Output is correct
9 Correct 380 ms 208 KB Output is correct
10 Correct 987 ms 208 KB Output is correct
11 Correct 673 ms 208 KB Output is correct
12 Correct 927 ms 208 KB Output is correct
13 Correct 797 ms 208 KB Output is correct
14 Correct 13 ms 208 KB Output is correct
15 Correct 15 ms 208 KB Output is correct
16 Correct 51 ms 208 KB Output is correct
17 Correct 99 ms 208 KB Output is correct
18 Correct 162 ms 208 KB Output is correct
19 Correct 372 ms 208 KB Output is correct
20 Correct 260 ms 208 KB Output is correct
21 Correct 774 ms 208 KB Output is correct
22 Correct 774 ms 208 KB Output is correct
23 Correct 852 ms 208 KB Output is correct
24 Correct 841 ms 208 KB Output is correct
25 Correct 16 ms 208 KB Output is correct
26 Correct 14 ms 208 KB Output is correct
27 Correct 30 ms 208 KB Output is correct
28 Correct 38 ms 208 KB Output is correct
29 Correct 35 ms 208 KB Output is correct
30 Correct 218 ms 208 KB Output is correct
31 Correct 203 ms 208 KB Output is correct
32 Correct 198 ms 208 KB Output is correct
33 Correct 318 ms 208 KB Output is correct
34 Correct 312 ms 208 KB Output is correct
35 Correct 300 ms 208 KB Output is correct
36 Correct 979 ms 208 KB Output is correct
37 Correct 805 ms 208 KB Output is correct
38 Correct 901 ms 208 KB Output is correct
39 Correct 990 ms 208 KB Output is correct
40 Correct 768 ms 208 KB Output is correct
41 Correct 895 ms 208 KB Output is correct
42 Correct 888 ms 208 KB Output is correct
43 Correct 953 ms 208 KB Output is correct
44 Correct 809 ms 208 KB Output is correct
45 Correct 17 ms 208 KB Output is correct
46 Correct 16 ms 208 KB Output is correct
47 Correct 17 ms 208 KB Output is correct
48 Correct 41 ms 208 KB Output is correct
49 Correct 43 ms 208 KB Output is correct
50 Correct 258 ms 208 KB Output is correct
51 Correct 249 ms 208 KB Output is correct
52 Correct 278 ms 208 KB Output is correct
53 Correct 360 ms 208 KB Output is correct
54 Correct 292 ms 208 KB Output is correct
55 Correct 311 ms 208 KB Output is correct
56 Correct 807 ms 208 KB Output is correct
57 Correct 829 ms 208 KB Output is correct
58 Correct 795 ms 276 KB Output is correct
59 Correct 834 ms 208 KB Output is correct
60 Correct 776 ms 208 KB Output is correct
61 Correct 788 ms 208 KB Output is correct
62 Correct 836 ms 208 KB Output is correct
63 Correct 812 ms 208 KB Output is correct
64 Correct 829 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 208 KB Incorrect
2 Halted 0 ms 0 KB -