# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
311985 | kylych03 | Mechanical Doll (IOI18_doll) | C++14 | 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>
#include "grader.cpp"
using namespace std;
int vis[200002];
void create_circuit(int M, std::vector<int> A) {
int N = A.size();
std::vector<int> C(M + 1);
vector <int> X, Y;
for(int i = 0; i<M+1; i++)
C[i]=0;
C[0]=A[0];
int cnt = 1;
for (int i = 0; i <N; ++i) {
if(vis[A[i]]!=0){
if(i==N-1)
Y[vis[A[i]]-1]=0;
else
Y[vis[A[i]]-1]=A[i+1];
}
else{
C[A[i]] = -cnt;
if(i==N-1)
X.push_back(0);
else
X.push_back(A[i+1]);
Y.push_back(-cnt);
vis[A[i]]=cnt;
cnt++;
}
}
for(int i = 0; i < X.size(); i++){
if(Y[i]<0)
swap(Y[i],X[i]);
}
answer(C, X, Y);
}