Submission #713761

#TimeUsernameProblemLanguageResultExecution timeMemory
713761LittleOrangeMechanical Doll (IOI18_doll)C++17
37 / 100
119 ms14516 KiB
#include "doll.h" #include<bits/stdc++.h> using namespace std; using ll = int; 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; }else if (N==16){ ll GN = 1<<(__lg(N-1)+1); while (A.size()<GN) A.push_back(-1); A.push_back(0); vector<int> X(GN-1),Y(GN-1); ll it = 0; function<ll(ll,ll,ll)> dfs; dfs = [&](ll cnt, ll st, ll lv){ if (cnt==1){ return A[st+1]; } ll i = it++; X[i] = dfs(cnt-cnt/2,st,lv+1); Y[i] = dfs(cnt/2,st+(1<<lv),lv+1); return -1-i; }; dfs(GN,0,0); answer(C, X, Y); } A.push_back(0); vector<vector<ll>> nxt(M); for(ll i = 0;i<N;i++){ nxt[A[i]-1].push_back(A[i+1]); } for(auto &o : nxt){ if (o.size()>2) { ll old = o.back(); o.pop_back(); o.resize(1<<(__lg(o.size())+1),-1); o.back() = old; } } vector<int> X,Y; ll it = 0; vector<ll> CUR; ll root; function<ll(ll,ll,ll)> dfs; dfs = [&](ll cnt, ll st, ll lv){ //cerr << "dfs " << cnt << " " << st << " " << lv << " " << CUR[st] << "\n"; if (cnt==1){ return CUR[st]==-1?root:CUR[st]; } ll i = it++; X.emplace_back(); Y.emplace_back(); X[i] = dfs(cnt-cnt/2,st,lv+1); Y[i] = dfs(cnt/2,st+(1<<lv),lv+1); return -1-i; }; for(ll i = 0;i<M;i++){ CUR = nxt[i]; if (CUR.size()>1){ C[i+1] = root = -1-it; dfs(CUR.size(),0,0); }else if(CUR.size()==1){ C[i+1] = CUR[0]; } } for(ll i = 0;i<N;i++) { //cerr << "nxt " << i << ":"; //for(ll j : nxt[i]) cerr << " " << j; //cerr << "\n"; } answer(C, X, Y); }

Compilation message (stderr)

doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:18:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'int'} [-Wsign-compare]
   18 |   while (A.size()<GN) A.push_back(-1);
      |          ~~~~~~~~^~~
#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...