답안 #967516

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
967516 2024-04-22T09:59:17 Z Jarif_Rahman 가장 긴 여행 (IOI23_longesttrip) C++17
40 / 100
397 ms 612 KB
#include "longesttrip.h"
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;

vector<int> longest_trip(int n, int D){
    vector<int> A = {0}, B = {};
    for(int i = 1; i < n; i++){
        if(B.empty()){
             if(are_connected({A.back()}, {i})) A.push_back(i);
             else if(are_connected({A[0]}, {i})) A.insert(A.begin(), i);
             else B = {i};
        }
        else{
            if(are_connected({A.back()}, {i})) A.push_back(i);
            else if(are_connected({B.back()}, {i})) B.push_back(i);
            else{
                reverse(B.begin(), B.end());
                A.insert(A.end(), B.begin(), B.end());
                B.clear();
                i--;
            }
        }
        if(A.size() < B.size()) swap(A, B);
    }

    int na = A.size(), nb = B.size();
    int ans = nb, x = -1, y = -1;

    for(int i = 0; i < nb; i++) for(int j = 0; j < na; j++){
        int cur = max(i+1, nb-i)+max(j+1, na-j);
        if(cur <= ans) continue;
        if(are_connected({B[i]}, {A[j]})) ans = cur, x = j, y = i;
    }

    vector<int> C = A;

    if(x != -1){
        C.clear();
        if(na-x > x+1){
            for(int i = na-1; i >= x; i--) C.push_back(A[i]);
        }
        else{
            for(int i = 0; i <= x; i++) C.push_back(A[i]);
        }

        if(nb-y > y+1){
            for(int i = y; i < nb; i++) C.push_back(B[i]);
        }
        else{
            for(int i = y; i >= 0; i--) C.push_back(B[i]);
        }
    }

    return C;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 596 KB Output is correct
2 Correct 5 ms 344 KB Output is correct
3 Correct 5 ms 344 KB Output is correct
4 Correct 4 ms 344 KB Output is correct
5 Correct 5 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 5 ms 596 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 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 5 ms 344 KB Output is correct
9 Correct 5 ms 344 KB Output is correct
10 Correct 5 ms 344 KB Output is correct
11 Correct 4 ms 344 KB Output is correct
12 Correct 6 ms 344 KB Output is correct
13 Correct 5 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 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 4 ms 344 KB Output is correct
5 Correct 4 ms 600 KB Output is correct
6 Correct 7 ms 344 KB Output is correct
7 Correct 5 ms 344 KB Output is correct
8 Correct 5 ms 344 KB Output is correct
9 Correct 6 ms 500 KB Output is correct
10 Correct 6 ms 600 KB Output is correct
11 Correct 4 ms 344 KB Output is correct
12 Correct 5 ms 600 KB Output is correct
13 Correct 4 ms 344 KB Output is correct
14 Correct 10 ms 344 KB Output is correct
15 Correct 12 ms 344 KB Output is correct
16 Correct 8 ms 344 KB Output is correct
17 Correct 6 ms 600 KB Output is correct
18 Correct 8 ms 600 KB Output is correct
19 Correct 5 ms 600 KB Output is correct
20 Correct 7 ms 612 KB Output is correct
21 Correct 5 ms 452 KB Output is correct
22 Correct 6 ms 440 KB Output is correct
23 Correct 5 ms 444 KB Output is correct
24 Correct 6 ms 440 KB Output is correct
25 Correct 11 ms 340 KB Output is correct
26 Correct 14 ms 344 KB Output is correct
27 Correct 11 ms 596 KB Output is correct
28 Correct 14 ms 344 KB Output is correct
29 Correct 9 ms 344 KB Output is correct
30 Correct 8 ms 344 KB Output is correct
31 Correct 66 ms 344 KB Output is correct
32 Correct 84 ms 344 KB Output is correct
33 Correct 9 ms 344 KB Output is correct
34 Correct 17 ms 344 KB Output is correct
35 Correct 33 ms 344 KB Output is correct
36 Correct 10 ms 344 KB Output is correct
37 Correct 64 ms 600 KB Output is correct
38 Correct 178 ms 600 KB Output is correct
39 Correct 367 ms 600 KB Output is correct
40 Correct 352 ms 600 KB Output is correct
41 Correct 388 ms 344 KB Output is correct
42 Correct 368 ms 600 KB Output is correct
43 Correct 397 ms 344 KB Output is correct
44 Correct 356 ms 348 KB Output is correct
45 Correct 8 ms 344 KB Output is correct
46 Correct 10 ms 344 KB Output is correct
47 Correct 9 ms 344 KB Output is correct
48 Correct 8 ms 344 KB Output is correct
49 Correct 9 ms 344 KB Output is correct
50 Correct 8 ms 344 KB Output is correct
51 Correct 53 ms 344 KB Output is correct
52 Correct 63 ms 344 KB Output is correct
53 Correct 7 ms 344 KB Output is correct
54 Correct 15 ms 600 KB Output is correct
55 Correct 18 ms 600 KB Output is correct
56 Correct 7 ms 344 KB Output is correct
57 Correct 43 ms 344 KB Output is correct
58 Correct 144 ms 344 KB Output is correct
59 Correct 241 ms 596 KB Output is correct
60 Correct 246 ms 344 KB Output is correct
61 Correct 272 ms 344 KB Output is correct
62 Correct 150 ms 600 KB Output is correct
63 Correct 369 ms 344 KB Output is correct
64 Correct 311 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 5 ms 596 KB Output is correct
4 Correct 5 ms 344 KB Output is correct
5 Correct 5 ms 344 KB Output is correct
6 Correct 9 ms 344 KB Output is correct
7 Correct 5 ms 344 KB Output is correct
8 Correct 5 ms 344 KB Output is correct
9 Correct 4 ms 596 KB Output is correct
10 Correct 5 ms 600 KB Output is correct
11 Correct 5 ms 344 KB Output is correct
12 Correct 6 ms 344 KB Output is correct
13 Correct 6 ms 600 KB Output is correct
14 Correct 11 ms 344 KB Output is correct
15 Correct 13 ms 344 KB Output is correct
16 Incorrect 1 ms 344 KB Incorrect
17 Halted 0 ms 0 KB -