Submission #1080487

# Submission time Handle Problem Language Result Execution time Memory
1080487 2024-08-29T10:25:49 Z aykhn Longest Trip (IOI23_longesttrip) C++17
15 / 100
10 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 
        {
            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 1 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 5 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 6 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 5 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 7 ms 344 KB Output is correct
8 Correct 5 ms 344 KB Output is correct
9 Correct 5 ms 432 KB Output is correct
10 Correct 5 ms 344 KB Output is correct
11 Correct 5 ms 436 KB Output is correct
12 Correct 5 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 7 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 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 5 ms 344 KB Output is correct
9 Correct 7 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 7 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 6 ms 344 KB Output is correct
16 Incorrect 1 ms 344 KB invalid array
17 Halted 0 ms 0 KB -
# 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 8 ms 344 KB Output is correct
4 Correct 7 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 5 ms 344 KB Output is correct
9 Correct 6 ms 344 KB Output is correct
10 Correct 5 ms 344 KB Output is correct
11 Correct 5 ms 420 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 10 ms 344 KB Output is correct
16 Incorrect 1 ms 344 KB invalid array
17 Halted 0 ms 0 KB -