Submission #138990

#TimeUsernameProblemLanguageResultExecution timeMemory
138990MAMBAMechanical Doll (IOI18_doll)C++17
6 / 100
146 ms14736 KiB
#include "doll.h" #include <bits/stdc++.h> using namespace std; #define rep(i , j , k) for(int i = j; i < (int)k; i++) #define pb push_back typedef vector<int> vi; const int N = 2e5 + 10; vi C , X ,Y, nx[N]; int n, cnt = 1; int build2(vi &vec , int l = 0, int r = -1) { if (r == -1) r = vec.size(); if (l == r - 1) return vec[l]; int mid = l + r >> 1; int me = cnt++; X.pb(0), Y.pb(0); int le = build2(vec , l , mid); int re = build2(vec , mid , r); X[me - 1] = le; Y[me - 1] = re; return -me; } void build(vi vec) { //if (vec.empty()) return; int sz = vec.size(); if(__builtin_popcount(sz) == 1) { build2(vec); return; } for (int i = 20; ~i; i--) if (sz > (1 << i) - 1) { vi local(vec.begin() , vec.begin() + (1 << i) - 1); local.pb(-(cnt + (1 << i) - 1)); build2(local); build(vi(vec.begin() + (1 << i) - 1 , vec.end())); break; } } void create_circuit(int M, vi A) { n = A.size(); A.pb(0); rep(i , 0 , n) nx[A[i]].pb(A[i + 1]); C.resize(M + 1); C[0] = A[0]; rep(i , 1 , M + 1) { if (nx[i].empty()) C[i] = 0; else if (nx[i].size() == 1) { C[i] = nx[i][0]; } else { C[i] = -cnt; build(nx[i]); } } answer(C , X , Y); return; }

Compilation message (stderr)

doll.cpp: In function 'int build2(vi&, int, int)':
doll.cpp:20:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   20 |  int mid = l + r >> 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...