Submission #980591

# Submission time Handle Problem Language Result Execution time Memory
980591 2024-05-12T09:08:17 Z 12345678 Longest Trip (IOI23_longesttrip) C++17
15 / 100
11 ms 608 KB
#include "longesttrip.h"
#include <bits/stdc++.h>

using namespace std;

const int nx=305;

std::vector<int> longest_trip(int N, int D)
{
    vector<int> d[2];
    d[0].push_back(0);
    d[1].push_back(1);
    bool not_connected=0;
    for (int i=2; i<N; i++)
    {
        if (are_connected(vector<int> {d[0].back()}, vector<int> {i}))
        {
            not_connected=0;
            d[0].push_back(i);
            continue;
        }
        if (not_connected||are_connected(vector<int> {d[1].back()}, vector<int> {i}))
        {
            not_connected=1;
            d[1].push_back(i);
            continue;
        }
        if (d[1].size()==1) not_connected=1;
        else not_connected=0;
        while (!d[1].empty()) d[0].push_back(d[1].back()), d[1].pop_back();
    }
    if (!are_connected(d[0], d[1])) return d[0].size()>d[1].size()?d[0]:d[1];
    if (are_connected(vector<int> {d[0].front()}, vector<int> {d[1].front()}))
    {
        reverse(d[0].begin(), d[0].end());
        for (auto x:d[1]) d[0].push_back(x);
        return d[0];
    }
    if (are_connected(vector<int> {d[0].front()}, vector<int> {d[1].back()}))
    {
        for (auto x:d[0]) d[1].push_back(x);
        return d[1];
    }
    if (are_connected(vector<int> {d[0].back()}, vector<int> {d[1].front()}))
    {
        for (auto x:d[1]) d[0].push_back(x);
        return d[0];
    }
    if (are_connected(vector<int> {d[0].back()}, vector<int> {d[1].back()}))
    {
        reverse(d[1].begin(), d[1].end());
        for (auto x:d[1]) d[0].push_back(x);
        return d[0];
    }
    int l=0, r=d[0].size()-1;
    while (l<r)
    {
        int md=(l+r)/2;
        vector<int> a;
        for (int i=0; i<=md; i++) a.push_back(d[0][i]);
        if (are_connected(a, d[1])) r=md;
        else l=md+1; 
    }
    int x=l;
    l=0, r=d[1].size()-1;
    while (l<r)
    {
        int md=(l+r)/2;
        vector<int> a;
        for (int i=0; i<=md; i++) a.push_back(d[1][i]);
        if (are_connected(a, vector<int> {d[0][x]})) r=md;
        else l=md+1;
    }
    vector<int> res;
    for (int i=x+1; i<d[0].size(); i++) res.push_back(d[0][i]);
    for (int i=0; i<=x; i++) res.push_back(d[0][i]);
    for (int i=l; i<d[1].size(); i++) res.push_back(d[1][i]);
    for (int i=0; i<l; i++) res.push_back(d[1][i]);
    return res;
}

Compilation message

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:75:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |     for (int i=x+1; i<d[0].size(); i++) res.push_back(d[0][i]);
      |                     ~^~~~~~~~~~~~
longesttrip.cpp:77:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |     for (int i=l; i<d[1].size(); i++) res.push_back(d[1][i]);
      |                   ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 2 ms 600 KB Incorrect
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 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 6 ms 344 KB Output is correct
5 Correct 5 ms 600 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 10 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 4 ms 436 KB Output is correct
10 Correct 6 ms 600 KB Output is correct
11 Correct 5 ms 600 KB Output is correct
12 Correct 4 ms 344 KB Output is correct
13 Correct 4 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 340 KB Output is correct
2 Correct 6 ms 344 KB Output is correct
3 Correct 4 ms 344 KB Output is correct
4 Correct 4 ms 344 KB Output is correct
5 Correct 4 ms 344 KB Output is correct
6 Correct 11 ms 596 KB Output is correct
7 Correct 5 ms 344 KB Output is correct
8 Correct 5 ms 344 KB Output is correct
9 Correct 4 ms 600 KB Output is correct
10 Correct 4 ms 600 KB Output is correct
11 Correct 5 ms 600 KB Output is correct
12 Correct 5 ms 344 KB Output is correct
13 Correct 4 ms 600 KB Output is correct
14 Incorrect 1 ms 344 KB invalid array
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 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 4 ms 344 KB Output is correct
5 Correct 4 ms 344 KB Output is correct
6 Correct 7 ms 344 KB Output is correct
7 Correct 5 ms 344 KB Output is correct
8 Correct 5 ms 344 KB Output is correct
9 Correct 5 ms 600 KB Output is correct
10 Correct 5 ms 608 KB Output is correct
11 Correct 5 ms 600 KB Output is correct
12 Correct 4 ms 344 KB Output is correct
13 Correct 5 ms 344 KB Output is correct
14 Incorrect 1 ms 344 KB invalid array
15 Halted 0 ms 0 KB -