Submission #713807

#TimeUsernameProblemLanguageResultExecution timeMemory
713807LittleOrangeMechanical Doll (IOI18_doll)C++17
10 / 100
1084 ms340 KiB
#include "doll.h" #include <bits/stdc++.h> using namespace std; using ll = int; const ll inf = 1e8; void create_circuit(int M, std::vector<int> A){ int N = A.size(); std::vector<int> C(M + 1, 0); C[0] = A[0]; if (N == 1){ for (int i = 1; i <= M; ++i) C[i] = 0; vector<int> X, Y; answer(C, X, Y); return; } for (int i = 1; i <= M; ++i){ C[i] = -1; } ll GN = 1 << (__lg(N - 1) + 1); A.push_back(0); vector<int> X,Y; ll it = 0; function<ll(ll, ll)> dfs; dfs = [&](ll cnt, ll width){ if (cnt == 1){ return inf; } ll i = it++; X.emplace_back(); Y.emplace_back(); if (width>=cnt*2){ X[i] = -1; Y[i] = dfs(cnt,width/2); }else{ ll leftsize = 1<<__lg(cnt-1); X[i] = dfs(leftsize,leftsize); Y[i] = dfs(cnt-leftsize,leftsize); } return -1 - i; }; dfs(N, GN); ll ait = 1; ll cur = -1; vector<ll> stat(X.size(),0); while(ait<=N){ ll *to; if (stat[-cur-1]){ to = &Y[-cur-1]; }else{ to = &X[-cur-1]; } stat[-cur-1]^=1; if (*to == inf){ *to = A[ait++]; cur = -1; }else{ cur = *to; } } 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...