Submission #1080498

# Submission time Handle Problem Language Result Execution time Memory
1080498 2024-08-29T10:33:38 Z aykhn Longest Trip (IOI23_longesttrip) C++17
15 / 100
14 ms 436 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 
        {
            assert(are_connected({p1.back()}, {p2.back()}));
            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
    {
        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 6 ms 344 KB Output is correct
2 Correct 6 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 6 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 6 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 9 ms 344 KB Output is correct
8 Correct 5 ms 344 KB Output is correct
9 Correct 6 ms 436 KB Output is correct
10 Correct 5 ms 344 KB Output is correct
11 Correct 6 ms 432 KB Output is correct
12 Correct 5 ms 344 KB Output is correct
13 Correct 7 ms 436 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 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 8 ms 344 KB Output is correct
7 Correct 6 ms 344 KB Output is correct
8 Correct 6 ms 344 KB Output is correct
9 Correct 7 ms 436 KB Output is correct
10 Correct 5 ms 344 KB Output is correct
11 Correct 6 ms 344 KB Output is correct
12 Correct 5 ms 344 KB Output is correct
13 Correct 4 ms 344 KB Output is correct
14 Correct 5 ms 340 KB Output is correct
15 Correct 9 ms 344 KB Output is correct
16 Correct 7 ms 344 KB Output is correct
17 Correct 10 ms 344 KB Output is correct
18 Correct 7 ms 344 KB Output is correct
19 Correct 6 ms 344 KB Output is correct
20 Correct 8 ms 344 KB Output is correct
21 Correct 8 ms 344 KB Output is correct
22 Correct 10 ms 344 KB Output is correct
23 Correct 6 ms 344 KB Output is correct
24 Correct 6 ms 436 KB Output is correct
25 Correct 9 ms 344 KB Output is correct
26 Correct 14 ms 344 KB Output is correct
27 Correct 6 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 5 ms 344 KB Output is correct
31 Correct 11 ms 344 KB Output is correct
32 Correct 11 ms 344 KB Output is correct
33 Correct 4 ms 344 KB Output is correct
34 Correct 6 ms 344 KB Output is correct
35 Correct 10 ms 344 KB Output is correct
36 Correct 5 ms 344 KB Output is correct
37 Correct 9 ms 344 KB Output is correct
38 Correct 5 ms 344 KB Output is correct
39 Correct 7 ms 344 KB Output is correct
40 Correct 8 ms 344 KB Output is correct
41 Correct 10 ms 344 KB Output is correct
42 Correct 8 ms 344 KB Output is correct
43 Correct 9 ms 432 KB Output is correct
44 Correct 8 ms 344 KB Output is correct
45 Incorrect 1 ms 344 KB Incorrect
46 Halted 0 ms 0 KB -
# 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 6 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 9 ms 344 KB Output is correct
8 Correct 6 ms 344 KB Output is correct
9 Correct 6 ms 344 KB Output is correct
10 Correct 7 ms 344 KB Output is correct
11 Correct 6 ms 344 KB Output is correct
12 Correct 6 ms 344 KB Output is correct
13 Correct 5 ms 344 KB Output is correct
14 Correct 8 ms 344 KB Output is correct
15 Correct 8 ms 344 KB Output is correct
16 Correct 12 ms 344 KB Output is correct
17 Correct 8 ms 344 KB Output is correct
18 Correct 7 ms 344 KB Output is correct
19 Correct 8 ms 344 KB Output is correct
20 Correct 7 ms 344 KB Output is correct
21 Correct 7 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 6 ms 344 KB Output is correct
25 Correct 8 ms 344 KB Output is correct
26 Correct 5 ms 344 KB Output is correct
27 Correct 10 ms 344 KB Output is correct
28 Correct 11 ms 344 KB Output is correct
29 Correct 8 ms 344 KB Output is correct
30 Correct 8 ms 344 KB Output is correct
31 Correct 7 ms 344 KB Output is correct
32 Incorrect 1 ms 344 KB Incorrect
33 Halted 0 ms 0 KB -