Submission #526905

#TimeUsernameProblemLanguageResultExecution timeMemory
526905benson1029Mechanical Doll (IOI18_doll)C++14
84 / 100
93 ms15752 KiB
#include "doll.h" #include<bits/stdc++.h> using namespace std; int n, N; int x[800005], y[800005]; vector<int> C, X, Y; vector< pair< int, pair<int,int> > > v; int id; int dfs(int i, int ord, int dep) { int tmp = ++id; X.push_back(x[i]); Y.push_back(y[i]); if(x[i] < -1) { X[tmp-1] = -dfs(-x[i], ord, dep+1); } else if(x[i] == 1) { v.push_back({ord, {tmp-1, 0} }); } if(y[i] < -1) { Y[tmp-1] = -dfs(-y[i], ord+(1<<dep), dep+1); }else if(y[i] == 1) { v.push_back({ord+(1<<dep), {tmp-1, 1} }); } return tmp; } void create_circuit(int M, std::vector<int> A) { n = A.size(); A.push_back(0); N = 1; while(N < n) N*=2; int cnt = N-n; for(int i=N/2; i<N; i++) { if(cnt>0) { x[i] = -1; cnt--; } else { x[i] = 1; } if(cnt>0) { y[i] = -1; cnt--; } else { y[i] = 1; } } for(int i=N/2-1; i>=1; i--) { if(x[i*2] == -1 && y[i*2]==-1) { x[i] = -1; } else { x[i] = -i*2; } if(x[i*2+1]==-1 && y[i*2+1]==-1) { y[i] = -1; } else { y[i] = -(i*2+1); } } C.push_back(A[0]); for(int i=0; i<M; i++) C.push_back(-1); dfs(1, 0, 0); sort(v.begin(), v.end()); int ptr = 0; for(auto i:v) { if(i.second.second==0) { X[i.second.first] = A[++ptr]; } else { Y[i.second.first] = A[++ptr]; } } 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...