Submission #129084

#TimeUsernameProblemLanguageResultExecution timeMemory
129084Just_Solve_The_ProblemMechanical Doll (IOI18_doll)C++11
62 / 100
145 ms15144 KiB
#include <bits/stdc++.h> #include "doll.h" //#include "grader.cpp" using namespace std; const int maxn = (int)1e6 + 7; const int inf = (int)1e6 + 6; int sz; void solve5(int M, vector<int> A) { int N = A.size(); vector<int> C(M + 1); vector<int> X, Y; C[0] = A[0]; int tmp = N - 1; while (tmp > 0) { sz++; tmp >>= 1; } if (sz) C[1] = -1; else C[1] = 0; X.resize(sz); Y.resize(sz); tmp = N - 1; for (int i = 1; i <= sz; i++) { if ((tmp >> (sz - i)) & 1) { X[i - 1] = A[0]; } else { X[i - 1] = -1; } Y[i - 1] = ((i == sz) ? 0 : -(i + 1)); } answer(C, X, Y); } vector <int> X, Y; int cnt[maxn]; void add(int val, int v, int l, int r) { int mid = (l + r) >> 1; if (cnt[v + v] == cnt[v + v + 1]) { cnt[v + v + 1]++; if (mid + 1 == r) { Y[v + sz - 1] = val; } else { add(val, v + v + 1, mid + 1, r); } } else { cnt[v + v]++; if (l == mid) { X[v + sz - 1] = val; } else { add(val, v + v, l, mid); } } cnt[v]++; } void solve1234(int M, vector<int> A) { int N = A.size(); vector <int> C(M + 1, 0); vector <int> vec[M + 1]; C[0] = A[0]; if (N == 1) { answer(C, X, Y); return ; } for (int i = 0; i < N; i++) { vec[A[i]].push_back((i + 1 == N) ? 0 : A[i + 1]); } for (int i = 1; i <= M; i++) { if (vec[i].empty()) continue; if (vec[i].size() == 1) { C[i] = vec[i][0]; continue; } int asd = 0; while ((1 << asd) < vec[i].size()) { asd++; } C[i] = -(sz + 1); for (int j = 1; j < (1 << asd); j++) { X.push_back(-(sz + j + j)); Y.push_back(-(sz + j + j + 1)); cnt[j + j] = 0; cnt[j + j + 1] = 0; if (j + j >= (1 << asd)) X.back() = -(sz + 1); if (j + j + 1 >= (1 << asd)) Y.back() = -(sz + 1); cnt[j] = 0; } for (int j = vec[i].size() - 1; j >= 0; j--) { add(vec[i][j], 1, 0, (1 << asd) - 1); } sz += (1 << asd) - 1; } //for (int i = 0; i < X.size(); i++) { //cout << X[i] << ' ' << Y[i] << '\n'; //} //for (int to : C) { //cout << to << ' '; //} //cout << endl; answer(C, X, Y); } void create_circuit(int M, vector<int> A) { if (M == 1) { solve5(M, A); } else { solve1234(M, A); } } /* 3 20 1 1 1 1 2 2 2 2 1 1 1 1 2 2 2 2 3 3 3 3 4 2 1 2 3 5 1 2 1 2 2 */

Compilation message (stderr)

doll.cpp: In function 'void solve1234(int, std::vector<int>)':
doll.cpp:80:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |   while ((1 << asd) < vec[i].size()) {
      |          ~~~~~~~~~~~^~~~~~~~~~~~~~~
#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...