Submission #1052737

# Submission time Handle Problem Language Result Execution time Memory
1052737 2024-08-10T20:08:12 Z Itamar Mechanical Doll (IOI18_doll) C++14
Compilation error
0 ms 0 KB
using namespace std;
#include<vector>

//void answer(std::vector<int> C, std::vector<int> X, std::vector<int> Y);

int find_s(int M, vector<int> A){
  int N = A.size();
  A.push_back(0);
  std::vector<int> C(M + 1,19);
  std::vector<int> X(2*N+1), Y(2*N+1);
  int l = 0, r = N;
  int wr = 0;
  while(l<r){
    int rt = l-1;
    int lt = rt - (r-l)/2;
    int it = r;
    for(int i = lt; i<=rt; i++){
        if(r == N){
            Y[wr]=it;
          it--;
          if(it >=l){
          X[wr]=it;
          }else{
          X[wr] = 2;
          }
          it--;wr++;
        }
        else{
          Y[wr]=it;
        it--;
        if(it >=l){
          X[wr]=it;
        }else{
          X[wr] = 2;
        }
        it--,wr++;
        }
    }
    l=lt,r=rt;
  }
  return l;
}
#include <algorithm>
#define vi vector<int>
vi getper(int N){
  if(N==1)return {0};
    vi per1= getper(N/2), per2 = getper((N+1)/2);
    vi ans;
    for(int i = 0; i < N; i++){
      if(i%2){
          ans.push_back(per1[i/2]+(N+1)/2);
      }else{
        ans.push_back(per2[i/2]);
      }
    }
    return ans;
}
void create_circuit(int M, std::vector<int> A) {

  int s = find_s(M,A);
  int N = A.size();
  vector<int> per;
  A.push_back(0);
  std::vector<int> C(M + 1,s);
  std::vector<int> X(-s), Y(-s);
  int l = 0, r = N;
  int wr = 0;
  while(l<r){
    int rt = l-1;
    int lt = rt - (r-l)/2;
    int it = r;
    for(int i = lt; i<=rt; i++){
        if(r == N){
            Y[wr]=it;
          it--;
          if(it != r-1 || (r-l)%2){
          X[wr]=it;
          it--;
          }else{
          X[wr] = s;
          }
          wr++;
        }
        else{
          Y[wr]=it;
        it--;
        if(it != r-1 || (r-l)%2){
          X[wr]=it;
          it--;
        }else{
          X[wr] = s;
        }
        wr++;
        }
    }
    l=lt,r=rt;
  }
  int st = s;
  while(st!=N){
    if(st < 0){
      int stag = X[-1-st];
      swap(X[-1-st],Y[-1-st]);
      st = stag;
    }else{
      per.push_back(st);
      st = s;
    }
  }
  per.push_back(N);
  vi q(N+1);
  for(int i = 0; i <= N; i++)q[per[i]]=i;
  for(int i = 0; i< (-s); i++){
    if(X[i]>=0)X[i] = A[q[X[i]]];
    if(Y[i]>=0)Y[i] = A[q[Y[i]]];
  }
  per.push_back(0);
  answer(C,X,Y);
}

Compilation message

doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:117:3: error: 'answer' was not declared in this scope
  117 |   answer(C,X,Y);
      |   ^~~~~~