Submission #894258

#TimeUsernameProblemLanguageResultExecution timeMemory
894258boxThe Collection Game (BOI21_swaps)C++17
100 / 100
5 ms1208 KiB
/* https://en.wikipedia.org/wiki/Batcher_odd%E2%80%93even_mergesort */ #include <bits/stdc++.h> using namespace std; #define ar array #define sz(v) static_cast<int>(v.size()) #define all(v) (v).begin(), (v).end() typedef pair<int, int> pi; typedef long long ll; typedef vector<int> vi; #if 0 void solve(int n, int v); void schedule(int i, int j); vi visit(); void answer(vi v); #else #include "swaps.h" #endif void solve(int n, int v) { vi p(n); iota(all(p), 1); vector<pair<int, int>> t; auto sch = [&](int i, int j) { schedule(p[i], p[j]); t.push_back({i, j}); }; auto vis = [&]() { if (sz(t)) { vi v = visit(); for (int h = 0; h < sz(t); h++) if (!v[h]) { auto [i, j] = t[h]; swap(p[i], p[j]); } t.clear(); } }; for (int p = 1; p < n; p *= 2) for (int k = p; k >= 1; k /= 2) { for (int j = k % p; j < n - k; j += k * 2) for (int i = 0; i < min(k, n - j - k); i++) if ((i + j) / (p * 2) == (i + j + k) / (p * 2)) sch(i + j, i + j + k); vis(); } answer(p); }
#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...
#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...