Submission #847604

# Submission time Handle Problem Language Result Execution time Memory
847604 2023-09-10T04:08:37 Z dlalswp25 Longest Trip (IOI23_longesttrip) C++17
100 / 100
11 ms 856 KB
#include "longesttrip.h"
#include <bits/stdc++.h>

using namespace std;

bool ask(vector<int> a, vector<int> b) {
    if (!a.size() || !b.size()) return false;
    return are_connected(a, b);
}

bool adj(int a, int b) {
    return ask({a}, {b});
}

std::vector<int> longest_trip(int N, int D)
{
    vector<int> A = {0}, B;
    for (int i = 1; i < N; i++) {
        if (!B.size()) {
            (adj(A.back(), i) ? A : B).push_back(i);
        } else if (!adj(A.back(), i)) {
            B.push_back(i);
        } else if (i < N - 1) {
            int j = i++;
            if (adj(B.back(), i)) {
                A.push_back(j);
                B.push_back(i);
                if (adj(j, i)) {
                    while (B.size()) {
                        A.push_back(B.back());
                        B.pop_back();
                    }
                }
            } else {
                if (adj(j, i)) {
                    A.push_back(j);
                    A.push_back(i);
                } else {
                    A.push_back(i);
                    B.push_back(j);
                }
            }
        } else {
            A.push_back(i);
            if (adj(B.back(), i)) {
                while (B.size()) {
                    A.push_back(B.back());
                    B.pop_back();
                }
            }
        }
    }
    if (!B.size()) return A;
    if (!ask(A, B)) return (A.size() > B.size() ? A : B);
    if (adj(A.back(), B[0])) {
        A.insert(A.end(), B.begin(), B.end());
        return A;
    }
    if (adj(A[0], B[0])) {
        reverse(A.begin(), A.end());
        A.insert(A.end(), B.begin(), B.end());
        return A;
    }
    vector<int> X = A;
    while (X.size() > 1) {
        vector<int> L, R;
        for (int i = 0; i < X.size(); i++) {
            if (i < X.size() / 2) L.push_back(X[i]);
            else R.push_back(X[i]);
        }
        if (ask(L, B)) X = L;
        else X = R;
    }
    int a = X[0];
    X = B;
    while (X.size() > 1) {
        vector<int> L, R;
        for (int i = 0; i < X.size(); i++) {
            if (i < X.size() / 2) L.push_back(X[i]);
            else R.push_back(X[i]);
        }
        if (ask({a}, L)) X = L;
        else X = R;
    }
    int b = X[0];
    vector<int> ans;
    int i;
    for (i = 0; i < A.size(); i++) {
        if (A[i] == a) break;
    }
    for (int j = (i + 1) % A.size(); j != i; j = (j + 1) % A.size()) {
        ans.push_back(A[j]);
    }
    ans.push_back(a);
    ans.push_back(b);
    for (i = 0; i < B.size(); i++) {
        if (B[i] == b) break;
    }
    for (int j = (i + 1) % B.size(); j != i; j = (j + 1) % B.size()) {
        ans.push_back(B[j]);
    }
    return ans;
}

Compilation message

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:67:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |         for (int i = 0; i < X.size(); i++) {
      |                         ~~^~~~~~~~~~
longesttrip.cpp:68:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |             if (i < X.size() / 2) L.push_back(X[i]);
      |                 ~~^~~~~~~~~~~~~~
longesttrip.cpp:78:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |         for (int i = 0; i < X.size(); i++) {
      |                         ~~^~~~~~~~~~
longesttrip.cpp:79:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |             if (i < X.size() / 2) L.push_back(X[i]);
      |                 ~~^~~~~~~~~~~~~~
longesttrip.cpp:88:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |     for (i = 0; i < A.size(); i++) {
      |                 ~~^~~~~~~~~~
longesttrip.cpp:96:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   96 |     for (i = 0; i < B.size(); i++) {
      |                 ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 344 KB Output is correct
2 Correct 7 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 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 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 600 KB Output is correct
6 Correct 8 ms 344 KB Output is correct
7 Correct 8 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 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 5 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 8 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 512 KB Output is correct
6 Correct 8 ms 344 KB Output is correct
7 Correct 6 ms 344 KB Output is correct
8 Correct 8 ms 344 KB Output is correct
9 Correct 6 ms 340 KB Output is correct
10 Correct 5 ms 344 KB Output is correct
11 Correct 6 ms 600 KB Output is correct
12 Correct 5 ms 600 KB Output is correct
13 Correct 5 ms 600 KB Output is correct
14 Correct 7 ms 344 KB Output is correct
15 Correct 11 ms 352 KB Output is correct
16 Correct 9 ms 344 KB Output is correct
17 Correct 8 ms 596 KB Output is correct
18 Correct 6 ms 344 KB Output is correct
19 Correct 6 ms 600 KB Output is correct
20 Correct 5 ms 600 KB Output is correct
21 Correct 7 ms 344 KB Output is correct
22 Correct 6 ms 344 KB Output is correct
23 Correct 5 ms 344 KB Output is correct
24 Correct 5 ms 436 KB Output is correct
25 Correct 8 ms 344 KB Output is correct
26 Correct 9 ms 344 KB Output is correct
27 Correct 9 ms 400 KB Output is correct
28 Correct 7 ms 344 KB Output is correct
29 Correct 8 ms 344 KB Output is correct
30 Correct 5 ms 344 KB Output is correct
31 Correct 6 ms 344 KB Output is correct
32 Correct 6 ms 344 KB Output is correct
33 Correct 7 ms 600 KB Output is correct
34 Correct 7 ms 600 KB Output is correct
35 Correct 6 ms 600 KB Output is correct
36 Correct 7 ms 600 KB Output is correct
37 Correct 7 ms 600 KB Output is correct
38 Correct 8 ms 436 KB Output is correct
39 Correct 6 ms 344 KB Output is correct
40 Correct 7 ms 600 KB Output is correct
41 Correct 9 ms 344 KB Output is correct
42 Correct 6 ms 344 KB Output is correct
43 Correct 6 ms 600 KB Output is correct
44 Correct 6 ms 600 KB Output is correct
45 Correct 8 ms 344 KB Output is correct
46 Correct 10 ms 344 KB Output is correct
47 Correct 7 ms 344 KB Output is correct
48 Correct 7 ms 596 KB Output is correct
49 Correct 9 ms 344 KB Output is correct
50 Correct 6 ms 432 KB Output is correct
51 Correct 7 ms 436 KB Output is correct
52 Correct 8 ms 344 KB Output is correct
53 Correct 6 ms 344 KB Output is correct
54 Correct 7 ms 344 KB Output is correct
55 Correct 7 ms 344 KB Output is correct
56 Correct 6 ms 440 KB Output is correct
57 Correct 6 ms 600 KB Output is correct
58 Correct 6 ms 436 KB Output is correct
59 Correct 8 ms 604 KB Output is correct
60 Correct 7 ms 600 KB Output is correct
61 Correct 6 ms 856 KB Output is correct
62 Correct 8 ms 440 KB Output is correct
63 Correct 8 ms 856 KB Output is correct
64 Correct 9 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 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 344 KB Output is correct
5 Correct 4 ms 344 KB Output is correct
6 Correct 8 ms 340 KB Output is correct
7 Correct 9 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 600 KB Output is correct
11 Correct 5 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 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 7 ms 432 KB Output is correct
20 Correct 6 ms 600 KB Output is correct
21 Correct 9 ms 344 KB Output is correct
22 Correct 8 ms 344 KB Output is correct
23 Correct 7 ms 344 KB Output is correct
24 Correct 7 ms 344 KB Output is correct
25 Correct 8 ms 344 KB Output is correct
26 Correct 6 ms 344 KB Output is correct
27 Correct 8 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 432 KB Output is correct
31 Correct 6 ms 600 KB Output is correct
32 Correct 8 ms 344 KB Output is correct
33 Correct 10 ms 344 KB Output is correct
34 Correct 7 ms 344 KB Output is correct
35 Correct 7 ms 344 KB Output is correct
36 Correct 10 ms 344 KB Output is correct
37 Correct 7 ms 440 KB Output is correct
38 Correct 7 ms 436 KB Output is correct
39 Correct 7 ms 344 KB Output is correct
40 Correct 7 ms 344 KB Output is correct
41 Correct 7 ms 344 KB Output is correct
42 Correct 7 ms 344 KB Output is correct
43 Correct 7 ms 600 KB Output is correct
44 Correct 5 ms 600 KB Output is correct
45 Correct 5 ms 344 KB Output is correct
46 Correct 5 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 9 ms 344 KB Output is correct
50 Correct 6 ms 344 KB Output is correct
51 Correct 6 ms 344 KB Output is correct
52 Correct 7 ms 344 KB Output is correct
53 Correct 8 ms 344 KB Output is correct
54 Correct 7 ms 852 KB Output is correct
55 Correct 7 ms 600 KB Output is correct
56 Correct 7 ms 344 KB Output is correct
57 Correct 9 ms 600 KB Output is correct
58 Correct 8 ms 344 KB Output is correct
59 Correct 7 ms 344 KB Output is correct
60 Correct 6 ms 344 KB Output is correct
61 Correct 6 ms 596 KB Output is correct
62 Correct 5 ms 444 KB Output is correct
63 Correct 7 ms 600 KB Output is correct
64 Correct 7 ms 604 KB Output is correct
65 Correct 7 ms 600 KB Output is correct
66 Correct 9 ms 600 KB Output is correct
67 Correct 7 ms 856 KB Output is correct
68 Correct 8 ms 600 KB Output is correct
69 Correct 8 ms 692 KB Output is correct
70 Correct 7 ms 440 KB Output is correct
71 Correct 8 ms 684 KB Output is correct
72 Correct 7 ms 600 KB Output is correct
73 Correct 7 ms 600 KB Output is correct
74 Correct 6 ms 436 KB Output is correct
75 Correct 7 ms 444 KB Output is correct
76 Correct 8 ms 756 KB Output is correct
77 Correct 8 ms 600 KB Output is correct
78 Correct 7 ms 444 KB Output is correct
79 Correct 8 ms 600 KB Output is correct
80 Correct 6 ms 444 KB Output is correct
81 Correct 7 ms 600 KB Output is correct
82 Correct 6 ms 600 KB Output is correct