Submission #1080491

# Submission time Handle Problem Language Result Execution time Memory
1080491 2024-08-29T10:27:51 Z aykhn Longest Trip (IOI23_longesttrip) C++17
15 / 100
12 ms 600 KB
#include "longesttrip.h"
#include <bits/stdc++.h>

using namespace std;

vector<int> longest_trip(int N, int D)
{
    vector<int> p1 = {0}, p2 = {1};
    for (int i = 2; i < N; i++)
    {
        if (are_connected({p1.back()}, {i})) p1.push_back(i);
        else if (are_connected({p2.back()}, {i})) p2.push_back(i);
        else 
        {
            while (!p2.empty()) 
            {
                p1.push_back(p2.back());
                p2.pop_back();
            }
            p2 = {i};
        }
    }
    if (p1.size() < p2.size()) swap(p1, p2);
    if (!are_connected(p1, p2)) return p1;
    if (are_connected({p1.back()}, {p2.back()}))
    {
        while (!p2.empty()) 
        {
            p1.push_back(p2.back());
            p2.pop_back();
        }
    }
    else if (are_connected({p1[0]}, {p2.back()}))
    {
        for (int &i : p1) p2.push_back(i);
        p1 = {};
        swap(p1, p2);
    }
    else if (are_connected({p1.back()}, {p2[0]}))
    {
        for (int &i : p2) p1.push_back(i);
        p2 = {};
    }
    else if (are_connected({p1[0]}, {p2[0]}))
    {
        reverse(p1.begin(), p1.end());
        for (int &i : p2) p1.push_back(i);
        p2 = {};
    }
    else
    {
        int l = 0, r = (int)p1.size() - 1;
        while (l < r)
        {
            int mid = (l + r) >> 1;
            vector<int> q;
            for (int i = l; i <= mid; i++) q.push_back(p1[i]);
            if (are_connected(q, {p2.back()})) r = mid;
            else l = mid + 1;
        }
        vector<int> nw = {p1[l]};
        for (int i = (l + 1) % (int)p1.size(); i != l; i = (i + 1) % (int)p1.size())
        {
            nw.push_back(p1[i]);
        }
        swap(nw, p1);
        for (int &i : p1) p2.push_back(i);
        swap(p1, p2);
    }
    return p1;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 2 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 7 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 6 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 6 ms 344 KB Output is correct
3 Correct 7 ms 384 KB Output is correct
4 Correct 5 ms 344 KB Output is correct
5 Correct 5 ms 436 KB Output is correct
6 Correct 8 ms 344 KB Output is correct
7 Correct 9 ms 344 KB Output is correct
8 Correct 7 ms 344 KB Output is correct
9 Correct 7 ms 344 KB Output is correct
10 Correct 5 ms 356 KB Output is correct
11 Correct 4 ms 344 KB Output is correct
12 Correct 5 ms 344 KB Output is correct
13 Correct 7 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 7 ms 340 KB Output is correct
3 Correct 5 ms 344 KB Output is correct
4 Correct 7 ms 344 KB Output is correct
5 Correct 7 ms 344 KB Output is correct
6 Correct 8 ms 344 KB Output is correct
7 Correct 9 ms 344 KB Output is correct
8 Correct 5 ms 340 KB Output is correct
9 Correct 6 ms 432 KB Output is correct
10 Correct 4 ms 344 KB Output is correct
11 Correct 4 ms 344 KB Output is correct
12 Correct 5 ms 344 KB Output is correct
13 Correct 7 ms 344 KB Output is correct
14 Correct 8 ms 344 KB Output is correct
15 Correct 7 ms 344 KB Output is correct
16 Correct 8 ms 344 KB Output is correct
17 Correct 5 ms 344 KB Output is correct
18 Correct 7 ms 344 KB Output is correct
19 Correct 7 ms 600 KB Output is correct
20 Correct 6 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 5 ms 600 KB Output is correct
24 Correct 6 ms 344 KB Output is correct
25 Correct 6 ms 344 KB Output is correct
26 Correct 7 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 7 ms 344 KB Output is correct
30 Correct 9 ms 344 KB Output is correct
31 Correct 5 ms 344 KB Output is correct
32 Correct 5 ms 344 KB Output is correct
33 Correct 5 ms 344 KB Output is correct
34 Correct 7 ms 344 KB Output is correct
35 Correct 6 ms 344 KB Output is correct
36 Correct 5 ms 344 KB Output is correct
37 Correct 5 ms 344 KB Output is correct
38 Correct 6 ms 344 KB Output is correct
39 Correct 9 ms 344 KB Output is correct
40 Correct 9 ms 436 KB Output is correct
41 Correct 8 ms 344 KB Output is correct
42 Correct 7 ms 344 KB Output is correct
43 Correct 9 ms 344 KB Output is correct
44 Correct 7 ms 344 KB Output is correct
45 Correct 9 ms 344 KB Output is correct
46 Correct 11 ms 344 KB Output is correct
47 Correct 11 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 5 ms 344 KB Output is correct
51 Incorrect 1 ms 344 KB Incorrect
52 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 7 ms 344 KB Output is correct
3 Correct 7 ms 344 KB Output is correct
4 Correct 6 ms 344 KB Output is correct
5 Correct 4 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 5 ms 344 KB Output is correct
9 Correct 5 ms 436 KB Output is correct
10 Correct 6 ms 344 KB Output is correct
11 Correct 4 ms 340 KB Output is correct
12 Correct 4 ms 344 KB Output is correct
13 Correct 7 ms 344 KB Output is correct
14 Correct 9 ms 344 KB Output is correct
15 Correct 10 ms 344 KB Output is correct
16 Correct 6 ms 344 KB Output is correct
17 Correct 7 ms 344 KB Output is correct
18 Correct 9 ms 344 KB Output is correct
19 Correct 8 ms 344 KB Output is correct
20 Correct 6 ms 344 KB Output is correct
21 Correct 9 ms 344 KB Output is correct
22 Correct 7 ms 344 KB Output is correct
23 Correct 6 ms 344 KB Output is correct
24 Correct 4 ms 344 KB Output is correct
25 Correct 9 ms 344 KB Output is correct
26 Correct 5 ms 344 KB Output is correct
27 Correct 8 ms 344 KB Output is correct
28 Correct 7 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 7 ms 344 KB Output is correct
32 Correct 9 ms 344 KB Output is correct
33 Correct 12 ms 344 KB Output is correct
34 Correct 8 ms 344 KB Output is correct
35 Correct 11 ms 344 KB Output is correct
36 Correct 9 ms 344 KB Output is correct
37 Correct 6 ms 344 KB Output is correct
38 Incorrect 1 ms 344 KB Incorrect
39 Halted 0 ms 0 KB -