Submission #696523

#TimeUsernameProblemLanguageResultExecution timeMemory
696523sharaelongMechanical Doll (IOI18_doll)C++17
2 / 100
42 ms8428 KiB
#include "doll.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; int rev(int x, int sz) { int k = 31 - __builtin_clz(sz); int ret = 0; for (int i=0; i<k; ++i) ret |= (1 << (k-1-i)) * ((x & (1 << i)) > 0); // cout << x << ' ' << sz << ' ' << ret << endl; return ret; } int switch_cnt = 0; vector<int> c, x, y; int build_single_circuit(vector<int> A) { int root = -switch_cnt-1; int n = A.size(); int offset = 0; // cout << n << endl; // for (int i: A) cout << i << ' '; // cout << endl; while (offset < n) { int sz = 1 << (31 - __builtin_clz(n-offset)); // cout << switch_cnt << ' ' << n << ' ' << sz << ' ' << offset << endl; for (int i=1; i<sz/2; ++i) { x.push_back(-(switch_cnt + 2*i)); y.push_back(-(switch_cnt + 2*i+1)); } for (int i=0; i<sz/2; ++i) { x.push_back(A[offset + rev(2*i, sz)]); // c[offset + rev(2*i, sz)] = -switch_cnt-1; if (i+1 < sz/2) { y.push_back(A[offset + rev(2*i+1, sz)]); // c[offset + rev(2*i+1, sz)] = -switch_cnt-1; } } if (n-offset == sz) { y.push_back(A.back()); break; } else { switch_cnt += sz-1; offset += sz-1; y.push_back(-switch_cnt-1); } } return root; } void create_circuit(int m, vector<int> A) { vector<vector<int>> go(m+1); for (int i=0; i+1<A.size(); ++i) go[A[i]].push_back(A[i+1]); go[A.back()].push_back(0); c.resize(m+1); c[0] = A[0]; for (int i=1; i<=m; ++i) { if (go[i].size() == 1) { c[i] = go[i][0]; } else if (go[i].size() >= 2) { c[i] = build_single_circuit(go[i]); } } // for (int i: c) cout << i << ' '; // cout << endl; // for (int i: x) cout << i << ' '; // cout << endl; // for (int i: y) cout << i << ' '; // cout << endl; answer(c, x, y); }

Compilation message (stderr)

doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:54:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |     for (int i=0; i+1<A.size(); ++i) go[A[i]].push_back(A[i+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...