Submission #967549

# Submission time Handle Problem Language Result Execution time Memory
967549 2024-04-22T12:13:42 Z Jarif_Rahman Longest Trip (IOI23_longesttrip) C++17
60 / 100
399 ms 600 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 > 1 && are_connected({A[0]}, {A.back()})){
            for(int i = x+1; i <= na+x; i++) C.push_back(A[i%na]);
        }
        else 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 > 1 && are_connected({B[0]}, {B.back()})){
            for(int i = y; i < nb+y; i++) C.push_back(B[i%nb]);
        }
        else 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;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 6 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 4 ms 344 KB Output is correct
# Verdict Execution time Memory 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 8 ms 344 KB Output is correct
7 Correct 7 ms 344 KB Output is correct
8 Correct 6 ms 344 KB Output is correct
9 Correct 4 ms 344 KB Output is correct
10 Correct 4 ms 600 KB Output is correct
11 Correct 4 ms 344 KB Output is correct
12 Correct 4 ms 344 KB Output is correct
13 Correct 5 ms 344 KB Output is correct
# Verdict Execution time Memory 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 6 ms 344 KB Output is correct
6 Correct 8 ms 344 KB Output is correct
7 Correct 6 ms 344 KB Output is correct
8 Correct 4 ms 540 KB Output is correct
9 Correct 4 ms 344 KB Output is correct
10 Correct 5 ms 344 KB Output is correct
11 Correct 5 ms 344 KB Output is correct
12 Correct 5 ms 600 KB Output is correct
13 Correct 4 ms 600 KB Output is correct
14 Correct 12 ms 344 KB Output is correct
15 Correct 12 ms 344 KB Output is correct
16 Correct 10 ms 344 KB Output is correct
17 Correct 6 ms 344 KB Output is correct
18 Correct 6 ms 432 KB Output is correct
19 Correct 5 ms 600 KB Output is correct
20 Correct 5 ms 344 KB Output is correct
21 Correct 5 ms 440 KB Output is correct
22 Correct 6 ms 436 KB Output is correct
23 Correct 6 ms 436 KB Output is correct
24 Correct 6 ms 440 KB Output is correct
25 Correct 9 ms 344 KB Output is correct
26 Correct 14 ms 344 KB Output is correct
27 Correct 13 ms 344 KB Output is correct
28 Correct 10 ms 344 KB Output is correct
29 Correct 10 ms 344 KB Output is correct
30 Correct 10 ms 344 KB Output is correct
31 Correct 67 ms 344 KB Output is correct
32 Correct 90 ms 344 KB Output is correct
33 Correct 8 ms 344 KB Output is correct
34 Correct 15 ms 344 KB Output is correct
35 Correct 28 ms 344 KB Output is correct
36 Correct 10 ms 344 KB Output is correct
37 Correct 66 ms 344 KB Output is correct
38 Correct 177 ms 344 KB Output is correct
39 Correct 290 ms 600 KB Output is correct
40 Correct 329 ms 344 KB Output is correct
41 Correct 385 ms 344 KB Output is correct
42 Correct 361 ms 600 KB Output is correct
43 Correct 362 ms 344 KB Output is correct
44 Correct 391 ms 600 KB Output is correct
45 Correct 12 ms 344 KB Output is correct
46 Correct 11 ms 344 KB Output is correct
47 Correct 8 ms 596 KB Output is correct
48 Correct 8 ms 344 KB Output is correct
49 Correct 9 ms 340 KB Output is correct
50 Correct 8 ms 344 KB Output is correct
51 Correct 50 ms 344 KB Output is correct
52 Correct 68 ms 344 KB Output is correct
53 Correct 7 ms 344 KB Output is correct
54 Correct 13 ms 600 KB Output is correct
55 Correct 19 ms 600 KB Output is correct
56 Correct 10 ms 596 KB Output is correct
57 Correct 53 ms 344 KB Output is correct
58 Correct 135 ms 344 KB Output is correct
59 Correct 230 ms 344 KB Output is correct
60 Correct 237 ms 344 KB Output is correct
61 Correct 278 ms 344 KB Output is correct
62 Correct 134 ms 344 KB Output is correct
63 Correct 351 ms 600 KB Output is correct
64 Correct 334 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 344 KB Output is correct
2 Correct 4 ms 344 KB Output is correct
3 Correct 4 ms 344 KB Output is correct
4 Correct 4 ms 344 KB Output is correct
5 Correct 4 ms 344 KB Output is correct
6 Correct 7 ms 344 KB Output is correct
7 Correct 6 ms 344 KB Output is correct
8 Correct 4 ms 344 KB Output is correct
9 Correct 5 ms 344 KB Output is correct
10 Correct 4 ms 344 KB Output is correct
11 Correct 4 ms 344 KB Output is correct
12 Correct 4 ms 344 KB Output is correct
13 Correct 5 ms 340 KB Output is correct
14 Correct 9 ms 344 KB Output is correct
15 Correct 12 ms 344 KB Output is correct
16 Correct 9 ms 344 KB Output is correct
17 Correct 7 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 6 ms 600 KB Output is correct
21 Correct 10 ms 344 KB Output is correct
22 Correct 14 ms 344 KB Output is correct
23 Correct 10 ms 344 KB Output is correct
24 Correct 9 ms 596 KB Output is correct
25 Correct 13 ms 344 KB Output is correct
26 Correct 9 ms 344 KB Output is correct
27 Partially correct 57 ms 344 KB Output is partially correct
28 Partially correct 91 ms 344 KB Output is partially correct
29 Correct 9 ms 344 KB Output is correct
30 Correct 18 ms 344 KB Output is correct
31 Partially correct 28 ms 344 KB Output is partially correct
32 Correct 9 ms 344 KB Output is correct
33 Correct 12 ms 344 KB Output is correct
34 Correct 9 ms 344 KB Output is correct
35 Correct 13 ms 344 KB Output is correct
36 Correct 10 ms 344 KB Output is correct
37 Correct 7 ms 344 KB Output is correct
38 Partially correct 45 ms 344 KB Output is partially correct
39 Partially correct 64 ms 344 KB Output is partially correct
40 Correct 7 ms 600 KB Output is correct
41 Correct 13 ms 600 KB Output is correct
42 Partially correct 18 ms 344 KB Output is partially correct
43 Correct 5 ms 440 KB Output is correct
44 Correct 5 ms 440 KB Output is correct
45 Correct 6 ms 440 KB Output is correct
46 Correct 5 ms 436 KB Output is correct
47 Partially correct 8 ms 344 KB Output is partially correct
48 Partially correct 60 ms 600 KB Output is partially correct
49 Partially correct 185 ms 344 KB Output is partially correct
50 Partially correct 348 ms 512 KB Output is partially correct
51 Partially correct 335 ms 600 KB Output is partially correct
52 Partially correct 352 ms 344 KB Output is partially correct
53 Partially correct 399 ms 344 KB Output is partially correct
54 Partially correct 360 ms 344 KB Output is partially correct
55 Partially correct 375 ms 600 KB Output is partially correct
56 Partially correct 54 ms 344 KB Output is partially correct
57 Partially correct 183 ms 344 KB Output is partially correct
58 Partially correct 334 ms 344 KB Output is partially correct
59 Partially correct 360 ms 344 KB Output is partially correct
60 Partially correct 337 ms 344 KB Output is partially correct
61 Partially correct 375 ms 600 KB Output is partially correct
62 Partially correct 7 ms 344 KB Output is partially correct
63 Partially correct 47 ms 344 KB Output is partially correct
64 Partially correct 146 ms 344 KB Output is partially correct
65 Partially correct 235 ms 344 KB Output is partially correct
66 Partially correct 223 ms 344 KB Output is partially correct
67 Partially correct 271 ms 600 KB Output is partially correct
68 Partially correct 131 ms 344 KB Output is partially correct
69 Partially correct 348 ms 344 KB Output is partially correct
70 Partially correct 348 ms 344 KB Output is partially correct
71 Partially correct 45 ms 344 KB Output is partially correct
72 Partially correct 175 ms 600 KB Output is partially correct
73 Partially correct 195 ms 344 KB Output is partially correct
74 Partially correct 189 ms 344 KB Output is partially correct
75 Partially correct 218 ms 344 KB Output is partially correct
76 Partially correct 302 ms 600 KB Output is partially correct
77 Partially correct 41 ms 344 KB Output is partially correct
78 Partially correct 111 ms 344 KB Output is partially correct
79 Partially correct 196 ms 344 KB Output is partially correct
80 Partially correct 242 ms 436 KB Output is partially correct
81 Partially correct 295 ms 344 KB Output is partially correct
82 Partially correct 138 ms 344 KB Output is partially correct