Submission #75333

#TimeUsernameProblemLanguageResultExecution timeMemory
75333XellosMechanical Doll (IOI18_doll)C++14
70.67 / 100
182 ms15960 KiB
#include <bits/stdc++.h> #include "doll.h" #define ff first #define ss second using namespace std; void create_circuit(int M, vector<int> A) { int N = A.size(); int dep = 1; while((1<<dep) < N+1) dep++; vector< vector< pair<int, int> > > son[2]; vector< vector<int> > state(dep); son[0].resize(dep); son[1].resize(dep); for(int i = 0; i < dep; i++) { state[i].resize(1<<i, 0); son[0][i].resize(1<<i, {i+1, -1}); son[1][i].resize(1<<i, {i+1, -1}); for(int j = 0; j < (1<<i); j++) { son[0][i][j].ss = 2*j; son[1][i][j].ss = 2*j+1; } } vector<int> order; for(int i = 0; i < (1<<dep); i++) { int cur = 0; for(int j = 0; j < dep; j++) { int nxt; if(state[j][cur]) nxt = son[1][j][cur].ss; else nxt = son[0][j][cur].ss; state[j][cur] ^= 1; cur = nxt; } order.push_back(cur); } vector<int> order_used; for(int i = 0; i < (1<<dep); i++) if(order[i] < N) order_used.push_back(order[i]); order_used.push_back(order.back()); vector< vector<int> > used(dep); for(int i = 0; i < dep; i++) used[i].resize(1<<i, 0); for(auto x: order_used) used[dep-1][x/2] = 1; for(int i = dep-2; i >= 0; i--) for(int j = 0; j < (1<<i); j++) if(used[i+1][2*j] || used[i+1][2*j+1]) used[i][j] = true; vector< vector<int> > id(dep); int S = 0; for(int i = 0; i < dep; i++) { id[i].resize(1<<i, -1); for(int j = 0; j < (1<<i); j++) if(used[i][j]) id[i][j] = S++; } vector<int> C(M+1, -1); vector<int> X(S, -1), Y(S, -1); for(int i = 0; i < dep-1; i++) for(int j = 0; j < (1<<i); j++) if(used[i][j]) { if(used[son[0][i][j].ff][son[0][i][j].ss]) X[id[i][j]] = -1-id[son[0][i][j].ff][son[0][i][j].ss]; if(used[son[1][i][j].ff][son[1][i][j].ss]) Y[id[i][j]] = -1-id[son[1][i][j].ff][son[1][i][j].ss]; } for(int i = 0; i <= N; i++) { int nxt = (i < N) ? A[i] : 0; int cur = order_used[i]/2; if(order_used[i]%2 == 0) X[id[dep-1][cur]] = nxt; else Y[id[dep-1][cur]] = nxt; } 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...