Submission #815747

#TimeUsernameProblemLanguageResultExecution timeMemory
815747rnl42Mechanical Doll (IOI18_doll)C++14
47 / 100
81 ms11208 KiB
#include "doll.h"
using namespace std;

int M, N;
vector<int> A;
vector<int> C, X, Y;
vector<bool> state;

void push(int* pos, int val) {
  while (*pos < 0) {
    state[-*pos-1].flip();
    pos = !state[-*pos-1] ? &X[-*pos-1] : &Y[-*pos-1];
  }
  int prev = *pos;
  *pos = -1-(int)X.size();
  state.push_back(true);
  X.push_back(prev);
  Y.push_back(val);
}

void create_circuit(int __M, vector<int> __A) {
  M = __M;
  A = __A;
  N = A.size();
  C.resize(M+1);
  X.reserve(3*N);
  Y.reserve(3*N);
  C[0] = A[0];
  C[A[0]] = A[1];
  for (int i = 2; i < N; i++) {
    push(&C[A[0]], A[i]);
  }
  for (int i = 1; i <= M; i++) {
    C[i] = -1;
  }
  int missing = (1<<__lg(2*N-1))-N;
  if (missing > 0) {
    for (int i = 0; i < missing; i++) {
      push(&C[1], -1);
    }
  }
  push(&C[A[0]], 0);

  answer(C, X, Y);
}
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...