Submission #526223

#TimeUsernameProblemLanguageResultExecution timeMemory
526223lkh3happyMechanical Doll (IOI18_doll)C++17
0 / 100
1 ms300 KiB
#include "doll.h" #include <bits/stdc++.h> using namespace std; int idx[400001], dir[400001], cnt; vector<int> c, x, y; void del(int n, int k){ if(n>=k) return; del(n*2, k); del(n*2+1, k); if(idx[n*2]==-1 && idx[n*2+1]==-1) idx[n]=-1; } int find(int n, int k){ if(n>=k) return n; if(!dir[n]){ dir[n]=1; return find(n*2, k); } else{ dir[n]=0; return find(n*2+1, k); } } void num(int n, int k){ if(n>=k || idx[n]) return; idx[n]=--cnt; num(n*2, k); num(n*2+1, k); } void ans(int n, int k){ if(n>=k || (n!=1 && idx[n]==-1)) return; x[-idx[n]-1]=idx[n*2]; y[-idx[n]-1]=idx[n*2+1]; ans(n*2, k); ans(n*2+1, k); } void create_circuit(int m, vector<int> A){ A.push_back(0); int n=A.size(), k=1; while(k<n) k*=2; for(int i=k+n;i<k+k;i++) idx[i]=-1; del(1, k); for(int i=0;i<n;i++){ int a=find(1, k); while(a>=k+n) a=find(1, k); idx[a]=A[i]; } num(1, k); for(int i=0;i<=m;i++) c.push_back(-1); x.resize(-cnt); y.resize(-cnt); ans(1, k); 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...