Submission #261133

#TimeUsernameProblemLanguageResultExecution timeMemory
261133NightlightMechanical Doll (IOI18_doll)C++14
12 / 100
58 ms10032 KiB
#include "doll.h" #include <bits/stdc++.h> #define LOG2(n) (31 - __builtin_clz(n)) #define pii pair<int, int> using namespace std; int N, M; int A[200005]; int tmp[200005]; int order[200005]; int to[200005]; int id[200005], pos[200005]; int X[200005], Y[200005]; int tot; int cnt = 2; void gen_order(int l, int r) { if(l == r) return; int mid = ((l + r) >> 1) + 1; for(int i = l; i <= r; i += 2) { tmp[l + (i - l) / 2] = order[i]; tmp[mid + (i - l) / 2] = order[i + 1]; } for(int i = l; i <= r; i++) order[i] = tmp[i]; gen_order(l, mid - 1), gen_order(mid, r); } int DFS(int l, int r) { int now; if(l + 1 == r) { if(to[l] == to[r]) return to[l]; if(l == 1 && r == tot) now = 1; else now = cnt++; X[now] = to[l], Y[now] = to[r]; // cout << -now << " -> " << X[now] << " " << Y[now] << "\n"; return -now; } int mid = (l + r) >> 1; int le = DFS(l, mid), ri = DFS(mid + 1, r); if(le == ri) return le; if(l == 1 && r == tot) now = 1; else now = cnt++; X[now] = le, Y[now] = ri; // cout << -now << " -> " << X[now] << " " << Y[now] << "\n"; return -now; } void solve() { tot = LOG2(N); if(N % (1 << tot) != 0) tot++; // cout << "tot -> " << tot << "\n"; tot = (1 << tot); for(int i = 1; i <= tot; i++) { order[i] = i; } gen_order(1, tot); // for(int i = 1; i <= tot; i++) cout << order[i] << " "; cout << "\n"; memset(to, -1, sizeof(to)); memset(tmp, -1, sizeof(tmp)); for(int i = tot; i > tot - N; i--) tmp[order[i]] = 1, pos[order[i]] = i; int p = 1; for(int i = 1; i <= N; i++) { while(tmp[p] == -1) p++; tmp[p] = A[i]; // cout << p << " " << A[i] << "\n"; p++; } assert(p == tot + 1); for(int i = 1; i <= tot; i++) { to[pos[i]] = tmp[i]; // assert(to[i] <= M); } DFS(1, tot); } void create_circuit(int m, vector<int> a) { a.emplace_back(0); M = m, N = a.size(); for(int i = 1; i <= N; i++) A[i] = a[i - 1]; vector<int> c(M + 1); for(int i = 0; i <= M; i++) c[i] = -1; solve(); vector<int> x(cnt - 1), y(cnt - 1); for(int i = 1; i < cnt; i++) { x[i - 1] = X[i]; // assert(x[i - 1] <= m); y[i - 1] = Y[i]; // assert(y[i - 1] <= m); } // system("pause"); answer(c, x, y); }
#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...