Submission #1240551

#TimeUsernameProblemLanguageResultExecution timeMemory
1240551dostsLongest Trip (IOI23_longesttrip)C++20
15 / 100
3 ms416 KiB
#include "longesttrip.h"
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2")
//#define int long long
#define pii pair<int,int>
#define vi vector<int>
#define ff first
#define ss second
#define sp << " " <<
#define all(x) x.begin(),x.end()
#define big(x) ((int)(x.size()))
using namespace std;
const int MOD = 1e9+7, LIM = 1e6+1, inf = 2e9;

std::vector<int> longest_trip(int N, int D)
{   
    deque<int> trip;
    if (D == 3) {
        for (int i=0;i<N;i++) trip.push_back(i);
        return vi(all(trip));
    }
    if (D == 2) {
        vi have(N,0);
        if (are_connected({0},{1})) {
            trip.push_back(0);
            trip.push_back(1);
            have[0] = have[1] = 1;
        }
        else {
            trip.push_back(0);
            trip.push_back(2);
            have[0] = have[2] = 1;
        }
        for (int i=1;i<N;i++) {
            if (have[i]) continue;
            if (are_connected({i},{trip.back()})) trip.push_back(i);
            else trip.push_front(i);
        }
        vi ans;
        while (!trip.empty()) {
            ans.push_back(trip.front());
            trip.pop_front();
        }
        return ans;
    }
    return {};
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...