Submission #415340

#TimeUsernameProblemLanguageResultExecution timeMemory
415340ruadhanMechanical Doll (IOI18_doll)C++17
0 / 100
1 ms204 KiB
#include <bits/stdc++.h> #include "doll.h" using namespace std; #define sz(x) (int)x.size() int S, N; vector<int> X, Y; vector<int> C; void build(int leaves_start, int node = 1) { if (node == 1) { X.resize(leaves_start - 1, -1), Y.resize(leaves_start - 1, -1); C[0] = -1; } if (2 * node < leaves_start) { X[node - 1] = -2 * node; build(leaves_start, 2 * node); } if (2 * node + 1 < leaves_start) { Y[node - 1] = -2 * node - 1; build(leaves_start, 2 * node + 1); } } void create_circuit(int M, vector<int> A) { N = A.size(); C.resize(M + 1); int binLog = -1; for (int i = 0; i < 20; i++) if ((1 << i) >= N) { binLog = i; break; } int pow2 = 1 << binLog; build(pow2); int start_leaf = 2 * pow2 - N; for (int i = 0; i < N; i++) { C[A[i]] = -1; if (i == N - 1) C[A[i]] = 0; int mask = i + (pow2 - N); int dest_node = 0; for (int j = 0; j < binLog; j++) if ((mask >> j) & 1) dest_node += 1 << (binLog - j - 1); dest_node += (1 << binLog); int parent = (dest_node) / 2; if (2 * parent == dest_node) { X[parent - 1] = A[i]; } else { Y[parent - 1] = A[i]; } } // cout << pow2 << '\n'; // for (auto x : C) // cout << x << " "; // cout << '\n'; // for (auto x : X) // cout << x << " "; // cout << '\n'; // for (auto x : Y) // cout << x << " "; // cout << '\n'; answer(C, X, Y); }

Compilation message (stderr)

doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:46:9: warning: unused variable 'start_leaf' [-Wunused-variable]
   46 |     int start_leaf = 2 * pow2 - N;
      |         ^~~~~~~~~~
#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...