Submission #295373

#TimeUsernameProblemLanguageResultExecution timeMemory
295373KastandaMechanical Doll (IOI18_doll)C++11
10 / 100
3 ms1868 KiB
// M #include<bits/stdc++.h> #include "doll.h" using namespace std; const int N = 400005; int n, m, k, len, A[N], L[N], R[N]; int M[N]; void DFS(int v, int tag) { assert(v <= len); if (M[v] == 0) { if (L[v] == 0) L[v] = tag; else DFS(-L[v], tag); } else { if (R[v] == 0) R[v] = tag; else DFS(-R[v], tag); } M[v] ^= 1; } 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); vector < int > X, Y; C[0] = A[0]; C[A[0]] = 0; answer(C, X, Y); return ; } if (0) { vector < int > C(m + 1, 0); vector < int > X, Y; for (int i = 0; i < n; i ++) C[A[i]] = A[i + 1]; C[0] = A[0]; answer(C, X, Y); return ; } k = 0; while ((1 << k) < n) k ++; memset(M, 0, sizeof(M)); 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}); }*/ } //sort(vec.begin(), vec.end()); int dummy = (1 << k) - 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; }*/ for (int i = 1; i <= n; i ++) DFS(1, A[i]); for (int i = 0; i < dummy; i ++) DFS(1, -1); for (int i = 1; i <= len; i ++) assert(M[i] == 0); 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...