Submission #713750

#TimeUsernameProblemLanguageResultExecution timeMemory
713750LittleOrangeMechanical Doll (IOI18_doll)C++17
53 / 100
84 ms9268 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); C[0] = A[0]; for (int i = 1; i <= M; ++i) C[i]=0; if (N == 1){ for (int i = 1; i <= M; ++i) C[i] = 0; vector<int> X,Y; answer(C, X, Y); return; } vector<ll> ctr(M); ll mxctr = 0; for(ll i : A) ctr[i-1]++; for(ll i : ctr) mxctr = max(mxctr,i); if (mxctr == 1){ vector<int> X,Y; A.push_back(0); for(ll i = 0;i<N;i++) C[A[i]] = A[i+1]; answer(C, X, Y); return; }else if (mxctr == 2){ ll it = 0; vector<ll> ptr(M); for(ll i = 0;i<M;i++){ if (ctr[i]==2) ptr[i] = it++,C[i+1] = -1-ptr[i]; } A.push_back(0); vector<ll> X(it,-1),Y(it,-1); for(ll i = 0;i<N;i++) { if (ctr[A[i]-1] == 1) C[A[i]] = A[i+1]; else{ if(X[ptr[A[i]-1]] == -1)X[ptr[A[i]-1]] = A[i+1]; else Y[ptr[A[i]-1]] = A[i+1]; } } answer(C, X, Y); return; } for (int i = 1; i <= M; ++i) { C[i] = -1; } 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); if (X.size()==0){ for(ll &i : C) if (i==-1) i = 0; } answer(C, X, Y); }

Compilation message (stderr)

doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:49:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'int'} [-Wsign-compare]
   49 |   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...