Submission #1080504

# Submission time Handle Problem Language Result Execution time Memory
1080504 2024-08-29T10:35:46 Z aykhn Longest Trip (IOI23_longesttrip) C++17
15 / 100
12 ms 852 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
    {
        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;
        }
        assert(are_connected({p1[l]}, {p2.back()}));
        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 1 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 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 5 ms 436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 344 KB Output is correct
2 Correct 8 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 9 ms 344 KB Output is correct
7 Correct 7 ms 344 KB Output is correct
8 Correct 8 ms 344 KB Output is correct
9 Correct 5 ms 440 KB Output is correct
10 Correct 5 ms 596 KB Output is correct
11 Correct 5 ms 344 KB Output is correct
12 Correct 8 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 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 7 ms 344 KB Output is correct
8 Correct 5 ms 344 KB Output is correct
9 Correct 8 ms 344 KB Output is correct
10 Correct 7 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 344 KB Output is correct
14 Correct 6 ms 344 KB Output is correct
15 Correct 7 ms 344 KB Output is correct
16 Correct 9 ms 344 KB Output is correct
17 Correct 10 ms 344 KB Output is correct
18 Correct 7 ms 852 KB Output is correct
19 Correct 6 ms 344 KB Output is correct
20 Correct 9 ms 344 KB Output is correct
21 Correct 8 ms 344 KB Output is correct
22 Correct 6 ms 344 KB Output is correct
23 Correct 5 ms 444 KB Output is correct
24 Correct 7 ms 440 KB Output is correct
25 Correct 4 ms 344 KB Output is correct
26 Correct 9 ms 344 KB Output is correct
27 Correct 5 ms 344 KB Output is correct
28 Correct 9 ms 344 KB Output is correct
29 Correct 7 ms 344 KB Output is correct
30 Correct 6 ms 344 KB Output is correct
31 Correct 9 ms 344 KB Output is correct
32 Correct 10 ms 344 KB Output is correct
33 Correct 5 ms 344 KB Output is correct
34 Correct 6 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 7 ms 344 KB Output is correct
39 Correct 9 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 8 ms 432 KB Output is correct
44 Correct 8 ms 344 KB Output is correct
45 Runtime error 1 ms 600 KB Execution killed with signal 6
46 Halted 0 ms 0 KB -
# 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 7 ms 344 KB Output is correct
5 Correct 7 ms 344 KB Output is correct
6 Correct 11 ms 344 KB Output is correct
7 Correct 8 ms 344 KB Output is correct
8 Correct 8 ms 344 KB Output is correct
9 Correct 5 ms 344 KB Output is correct
10 Correct 8 ms 344 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 6 ms 344 KB Output is correct
15 Correct 9 ms 344 KB Output is correct
16 Correct 12 ms 344 KB Output is correct
17 Correct 5 ms 596 KB Output is correct
18 Correct 9 ms 344 KB Output is correct
19 Correct 8 ms 436 KB Output is correct
20 Correct 10 ms 436 KB Output is correct
21 Correct 4 ms 340 KB Output is correct
22 Correct 8 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 7 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 5 ms 344 KB Output is correct
30 Correct 6 ms 344 KB Output is correct
31 Correct 6 ms 344 KB Output is correct
32 Runtime error 1 ms 600 KB Execution killed with signal 6
33 Halted 0 ms 0 KB -