Submission #97664

#TimeUsernameProblemLanguageResultExecution timeMemory
97664CRE_VIOUSMechanical Doll (IOI18_doll)C++14
100 / 100
171 ms14152 KiB
#include "doll.h" #include <bits/stdc++.h> using namespace std; struct Node { int ty, l, r; }; int N, cnts = 2; Node G[500009]; void create_circuit(int M, std::vector<int> A) { N = A.size(); N++; int dep = 0; for (int i = 0; i < 22; i++) { int Z = (1 << i); if (Z >= N) { dep = i; break; } } for (int i = 0; i < 500009; i++) G[i] = Node{0, -1, -1}; vector<int>T; T.push_back(1); for (int i = dep - 1; i >= 1; i--) { int A = (N + (1 << i) - 1) / (1 << i); vector<int> TT; int AL = 0, AR = A - 1; if (A % 2 == 1) { AL++; AR++; } for (int j = AL; j <= AR; j++) { if (j % 2 == 0) { G[T[j / 2]].l = cnts; TT.push_back(cnts); cnts++; } else { G[T[j / 2]].r = cnts; TT.push_back(cnts); cnts++; } } T = TT; } int BAR = T.size() * 2; for (int i = 1; i < cnts; i++) { if (G[i].r >= 1 && G[i].l == -1) G[i].l = 1; } for (int i = 0; i < BAR; i++) { int cx = 1, I = 0; if (i == BAR - 1) I = 0; else if (i < A.size()) I = A[i]; else I = -1; while (true) { if (G[cx].l <= -1) break; if (G[cx].ty == 0) { G[cx].ty ^= 1; cx = G[cx].l; } else { G[cx].ty ^= 1; cx = G[cx].r; } } if (G[cx].ty == 0) { G[cx].l = -I; } else { G[cx].r = -I; } G[cx].ty ^= 1; } vector<int>C, X, Y; for (int i = 0; i <= M; i++) C.push_back(-1); for (int i = 1; i < cnts; i++) { X.push_back(-G[i].l); Y.push_back(-G[i].r); } //cout<<"C = {"; for (int i = 0; i < C.size(); i++) { if(i) cout<<","; cout<<C[i]; } cout<<"}"<<endl; //cout<<"X = {"; for (int i = 0; i < X.size(); i++) { if(i) cout<<","; cout<<X[i]; } cout<<"}"<<endl; //cout<<"Y = {"; for (int i = 0; i < Y.size(); i++) { if(i) cout<<","; cout<<Y[i]; } cout<<"}"<<endl; answer(C, X, Y); }

Compilation message (stderr)

doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:41:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |   else if (i < A.size()) I = A[i];
      |            ~~^~~~~~~~~~
#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...