Submission #897332

# Submission time Handle Problem Language Result Execution time Memory
897332 2024-01-02T23:32:50 Z ksujay2 Longest Trip (IOI23_longesttrip) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

int bsmin(vector<int> A, vector<int> B) {
    int l = 0, r = A.size();
    while(l < r) {
        int m = l + (r - l) / 2;
        vector<int> C;
        for(int i = l; i <= m; i++) C.push_back(A[i]);
        if(are_connected(C, B)) {
            r = m;
        } else {
            l = m + 1;
        }
    }
    return l;
}

vector<int> longest_trip(int N, int D) {
    vector<int> o(N);
    for(int i = 0; i < N; i++) o[i] = i;
    int rng = N - 1;
    while(rng % 2 == 0) rng /= 2;
    for(int i = 0; i < N; i++) swap(o[i], o[(i * i * rng) % N]);
    vector<int> A, B;
    A.push_back(o[0]);
    bool not_con = false;
    for(int i = 1; i < N; i++) {
        if(are_connected({A.back()}, {o[i]})) {
            A.push_back(o[i]);
            not_con = false;
        } else {
            if(B.size() == 0 || not_con) {
                B.push_back(o[i]);
                not_con = true;
            } else {
                if(are_connected({B.back()}, {o[i]})) {
                    B.push_back(o[i]);
                    not_con = true;
                } else {
                    while(B.size() > 0) {
                        A.push_back(B.back());
                        B.pop_back();
                    }
                    B.push_back(o[i]);
                    not_con = false;
                }
            }
        }
    }
    if(A.size() < B.size()) swap(A, B);
    if(B.empty()) return A;
    if(are_connected({A[0]}, {B[0]})) reverse(A.begin(), A.end());
    if(are_connected({A.back()}, {B.back()})) reverse(B.begin(), B.end());
    if(are_connected({A[0]}, {B.back()})) reverse(A.begin(), A.end()), reverse(B.begin(), B.end());
    if(are_connected({A.back()}, {B[0]})) {
        for(int i : B) A.push_back(i);
        return A;
    }
    if(are_connected(A, B)) {
        int j = bsmin(A, B);
        int k = bsmin(B, {A[j]});
        rotate(A.begin(), A.begin() + (j + 1) % A.size(), A.end());
        rotate(B.begin(), B.begin() + k, B.end());
        for(int i : B) A.push_back(i);
        return A;
    }
    return A;
}

Compilation message

longesttrip.cpp: In function 'int bsmin(std::vector<int>, std::vector<int>)':
longesttrip.cpp:10:12: error: 'are_connected' was not declared in this scope
   10 |         if(are_connected(C, B)) {
      |            ^~~~~~~~~~~~~
longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:29:12: error: 'are_connected' was not declared in this scope
   29 |         if(are_connected({A.back()}, {o[i]})) {
      |            ^~~~~~~~~~~~~
longesttrip.cpp:53:8: error: 'are_connected' was not declared in this scope
   53 |     if(are_connected({A[0]}, {B[0]})) reverse(A.begin(), A.end());
      |        ^~~~~~~~~~~~~
longesttrip.cpp:54:8: error: 'are_connected' was not declared in this scope
   54 |     if(are_connected({A.back()}, {B.back()})) reverse(B.begin(), B.end());
      |        ^~~~~~~~~~~~~
longesttrip.cpp:55:8: error: 'are_connected' was not declared in this scope
   55 |     if(are_connected({A[0]}, {B.back()})) reverse(A.begin(), A.end()), reverse(B.begin(), B.end());
      |        ^~~~~~~~~~~~~
longesttrip.cpp:56:8: error: 'are_connected' was not declared in this scope
   56 |     if(are_connected({A.back()}, {B[0]})) {
      |        ^~~~~~~~~~~~~
longesttrip.cpp:60:8: error: 'are_connected' was not declared in this scope
   60 |     if(are_connected(A, B)) {
      |        ^~~~~~~~~~~~~