Submission #1225868

#TimeUsernameProblemLanguageResultExecution timeMemory
1225868Godgift42Fun Tour (APIO20_fun)C++20
0 / 100
0 ms328 KiB
#include "fun.h"

#include <vector>
#include <bits/stdc++.h>
using namespace std;


std::vector<int> createFunTour(int N, int Q) {
  vector<int> per(N);
  if(N==2){
    per[0]=0;
    per[1]=1;
    return per;
  }
  vector<int> bf1;
  vector<int>bf2;
  queue<int> q;
  q.push(1);
  while(!q.empty()){
    int u=q.front();
    bf1.push_back(u);
    q.pop();
    if(u*2+1<N)q.push(u*2+1);
    if(u*2+2<N)q.push(u*2+2);
  }
  q.push(2);
  while(!q.empty()){
    int u=q.front();
    bf2.push_back(u);
    q.pop();
    if(u*2+1<N)q.push(u*2+1);
    if(u*2+2<N)q.push(u*2+2);
  }
  reverse(bf1.begin(),bf1.end());
  reverse(bf2.begin(),bf2.end());
  bf1.push_back(0);
  int i=0;
  int j=0;
  bool ch=false;
  int cnt=0;
  while(cnt<N){
    per[cnt]=bf1[i];
    i++;
    cnt++;
    if(cnt==N)break;
    if(!ch){
      per[cnt]=bf2[j];
      j++;
      cnt++;
      if(j==bf2.size()){
        ch=true;
        j=bf1.size()-1;
      }
    }
    else{
      per[cnt]=bf1[j];
      j--;
      cnt++;
    }
  }

  return per;
}
#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...