Submission #938935

#TimeUsernameProblemLanguageResultExecution timeMemory
938935AdamGSLongest Trip (IOI23_longesttrip)C++17
25 / 100
8 ms608 KiB
#include "longesttrip.h"
#include<bits/stdc++.h>
using namespace std;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
vector<int>longest_trip(int n, int d) {
  vector<pair<int,int>>X, Y;
  vector<int>A, B;
  rep(i, n/2) if(are_connected({2*i}, {2*i+1})) X.pb({2*i, 2*i+1}); else Y.pb({2*i, 2*i+1});
  if(n%2==1) A.pb(n-1);
  for(auto i : X) {
    if(A.size()==0) {
      A.pb(i.st);
      A.pb(i.nd);
      continue;
    }
    if(B.size()==0) {
      B.pb(i.st);
      B.pb(i.nd);
      continue;
    }
    if(are_connected({A.back()}, {i.st})) {
      A.pb(i.st);
      A.pb(i.nd);
      continue;
    }
    if(are_connected({B.back()}, {i.st})) {
      B.pb(i.st);
      B.pb(i.nd);
      continue;
    }
    reverse(all(B));
    for(auto j : B) A.pb(j);
    B.clear();
    B.pb(i.st);
    B.pb(i.nd);
  }
  for(auto i : Y) {
    if(A.size()==0) {
      A.pb(i.st);
      B.pb(i.nd);
      continue;
    }
    if(!are_connected({A.back()}, {i.st})) swap(i.st, i.nd);
    A.pb(i.st);
    if(B.size()==0 || are_connected({B.back()}, {i.nd})) {
      B.pb(i.nd);
      continue;
    }
    reverse(all(B));
    for(auto j : B) A.pb(j);
    B.clear();
    B.pb(i.nd);
  }
  if(A.size()<B.size()) return B;
  return A;
}
#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...