Submission #1065274

# Submission time Handle Problem Language Result Execution time Memory
1065274 2024-08-19T05:40:53 Z deera Longest Trip (IOI23_longesttrip) C++17
Compilation error
0 ms 0 KB
#include "longesttrip.h"
#include <bits/stdc++.h>
using namespace std;

vector<int> solve_d3(int N, int D) {
    vector<int> res(N);
    iota(res.begin(), res.end(), 0);
    return res;
}

vector<int> solve_d2(int N, int D) {
    queue<int> stops;
    for (int i = 1; i < N; i++) stops.push(i);

    deque<int> trip = {0};
    while (stops.size() > 1) {
        int next = stops.front(); stops.pop();
        int last = trip.back();
        
        if (are_connected({next}, {last})) {
            trip.push_back(next);
        } else {
            trip.push_back(stops.front()); stops.pop();
            trip.push_back(next);
        }
    }

    if (stops.size() == 1) {
        int next = stops.front();
        int last = trip.back();
        if (are_connected({next}, {last})) {
            trip.push_back(next);
        } else {
            trip.push_front(stops.front()); stops.pop();
        }
    }

    vector<int> res;
    for (int x : trip) res.push_back(x);
    return res;
}

vector<int> longest_trip(int N, int D) {
    if (D == 3) return solve_d3(N, D);
    if (D == 2) return solve_d2(N, D);
}


signed main() {
    vector<int> trip = longest_trip(5, 3);
    for (auto x : trip) cout << x << ' ';
    cout << '\n';
}

Compilation message

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:46:1: warning: control reaches end of non-void function [-Wreturn-type]
   46 | }
      | ^
/usr/bin/ld: /tmp/ccoRAK6A.o: in function `main':
stub.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cc5BKecy.o:longesttrip.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status