제출 #295312

#제출 시각아이디문제언어결과실행 시간메모리
295312Kastanda자동 인형 (IOI18_doll)C++11
47 / 100
209 ms13972 KiB
// M #include<bits/stdc++.h> #include "doll.h" using namespace std; const int N = 400005; int n, m, A[N], L[N], R[N]; void create_circuit(int _m, vector < int > _A) { m = _m; n = (int)_A.size(); for (int i = 0; i < n; i ++) A[i] = _A[i]; A[n] = 0; if (n == 1) { vector < int > C(m + 1, 0); C[0] = A[0]; C[A[0]] = 0; vector < int > X, Y; answer(C, X, Y); return ; } int k = 0; while ((1 << k) < n) k ++; int len = (1 << k) - 1; vector < pair < int , int > > vec; for (int i = 1; i <= len; i ++) { if (i * 2 + 1 <= len) L[i] = -(i * 2), R[i] = -(i * 2 + 1); else { int ra = 0, a = i; while (a) ra = (ra << 1) | (a & 1), a >>= 1; vec.push_back({ra | (1 << k), i}); vec.push_back({ra, i}); } } assert((int)vec.size() == (1 << k)); sort(vec.begin(), vec.end()); for (int i = 1; i < (int)vec.size(); i ++) assert(vec[i].first != vec[i - 1].first); int dummy = (int)vec.size() - n; for (int i = 0; i < dummy; i ++) { int id = vec[i].second; int a = vec[i].first; if ((a >> k) & 1) R[id] = -1; else L[id] = -1; } for (int i = dummy; i < (int)vec.size(); i ++) { int j = A[i - dummy + 1]; int id = vec[i].second; int a = vec[i].first; if ((a >> k) & 1) R[id] = j; else L[id] = j; } vector < int > C(m + 1, -1); C[0] = A[0]; vector < int > X(len), Y(len); for (int i = 0; i < len; i ++) X[i] = L[i + 1], Y[i] = R[i + 1]; assert(len <= n + n); answer(C, X, Y); return ; }
#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...