# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
297639 | davi_bart | Mechanical Doll (IOI18_doll) | C++14 | 143 ms | 13192 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<bits/stdc++.h>
#include "doll.h"
using namespace std;
#define ll long long
#define fi first
#define se second
void answer(std::vector<int> C, std::vector<int> X, std::vector<int> Y);
void create_circuit(int M, std::vector<int> A) {
int N = A.size();
std::vector<int> C(M+1,0);
vector<int> X,Y;
vector<int> volte[M+2];
vector<bool> vis(M+2,0);
A.push_back(0);
for(int i=0;i<A.size()-1;i++){
volte[A[i]].push_back(A[i+1]);
}
C[0]=A[0];
int S=1;
for(int i=0;i<A.size()-1;i++){
int x=A[i];
if(volte[x].size()>=2){
if(vis[x])continue;
vis[x]=1;
int lg=32-__builtin_clz(volte[x].size());
vector<int> k(1<<lg);
for(int i=0;i<lg;i++){
for(int j=0;j<(1<<lg);j+=(1<<(lg-i))){
k[j+(1<<(lg-i-1))]=k[j]+(1<<i);
}
}
C[A[i]]=-S;
int q=volte[x].back();
volte[x].pop_back();
while(volte[x].size()<(1<<lg))volte[x].push_back(-S);
volte[x].pop_back();
volte[x].push_back(q);
//for(int a:volte[x])cout<<a<<" ";
//cout<<endl;
int s=S;
for(int i=1;i<(1<<lg);i++){
if(i<(1<<(lg-1))){
X.push_back(-(2*i+s-1));
Y.push_back(-(2*i+s));
}else{
X.push_back(volte[x][k[2*i-(1<<lg)]]);
Y.push_back(volte[x][k[2*i+1-(1<<lg)]]);
}
S++;
}
continue;
}
C[x]=A[i+1];
}
answer(C, X, Y);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |