Submission #911465

#TimeUsernameProblemLanguageResultExecution timeMemory
911465biankMechanical Doll (IOI18_doll)C++14
0 / 100
1 ms348 KiB
#include <bits/stdc++.h> #include "doll.h" using namespace std; #define SIZE(x) (int)x.size() #define forn(i,n) for(int i=0;i<int(n);i++) #define forsn(i,s,n) for(int i=int(s);i<int(n);i++) #define pb push_back typedef vector<int> vi; vi L, R, v, state; int t=0, skip, s=0; int build(int l, int r) { int u = t++; L.pb(0), R.pb(0), v.pb(0); assert(u>=0 && u<SIZE(v)); if(skip>0 && r-l+1<=skip) { v[u] = -1; skip -= r-l+1; return u; } if(l>=r) return u; v[u] = --s; int m=(l+r)/2; L[u] = build(l,m); R[u] = build(m+1,r); return u; } bool dfs(int u, int a) { assert(u>=0 && u<SIZE(v)); if(u!=0 && v[u]==-1) return false; if(!v[u]) { v[u]=a; return true; } state[u]^=1; assert(v[L[u]]!=-1 || v[R[u]]!=-1); if(state[u]) return dfs(L[u],a); return dfs(R[u],a); } void create_circuit(int m, vi A) { vi c(m+1); c[0]=A[0]; forsn(i,1,m+1) c[i]=-1; int n=SIZE(A), sz=1; while(sz<n) sz*=2; assert(sz>=n); skip=sz-n; build(0,sz-1); assert(SIZE(L)==SIZE(R) && SIZE(v)==SIZE(L)); vi a; forsn(i,1,n) a.pb(A[i]); a.pb(0); state.assign(SIZE(v),0); forn(i,n) { bool flag=0; while(!flag) flag=dfs(0,a[i]); } vi x, y; forn(i,SIZE(v)) { if(L[i] && R[i]) { x.pb(v[L[i]]); y.pb(v[R[i]]); } } 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...