# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
300994 | TMJN | Mechanical Doll (IOI18_doll) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "doll.h"
#include <bits/stdc++.h>
using namespace std;
void create_circuit(int M,vector<int>A) {
vector<int>X,Y,C(M+1,0);
A.push_back(0);
int f=0;
for(int i:A){
C[f]=i;
f=i;
}
vector<bool>B(400000,false);
int p=0;
vector<int>T;
do{
if(p>=0){
if(p)T.push_back(p);
p=C[p];
}
else{
if(B[-p-1]){
B[-p-1]=!B[-p-1];
p=Y[-p-1];
}
else{
B[-p-1]=!B[-p-1];
p=X[-p-1];
}
}
}while(p);
assert(A==T);
bool f=false;
for(int i=0;i<400000;i++){
f|=B[i];
}
assert(!f);
answer(C,X,Y);
}