Submission #502070

#TimeUsernameProblemLanguageResultExecution timeMemory
502070tengiz05Monster Game (JOI21_monster)C++17
100 / 100
111 ms292 KiB
#include "monster.h" #include <bits/stdc++.h> namespace { std::mt19937 rnd(std::chrono::steady_clock::now().time_since_epoch().count()); std::vector<int> sort(std::vector<int> a) { if (a.size() == 1) { return a; } int m = a.size() / 2; std::shuffle(a.begin(), a.end(), rnd); std::vector<int> l(a.begin(), a.begin() + m), r(a.begin() + m, a.end()); l = sort(l); r = sort(r); int i = 0, j = 0; for (int k = 0; k < int(a.size()); k++) { if (i == int(l.size())) { a[k] = r[j++]; } else if (j == int(r.size())) { a[k] = l[i++]; } else if (Query(l[i], r[j])) { a[k] = r[j++]; } else { a[k] = l[i++]; } } return a; } std::vector<int> slow(std::vector<int> a) { int n = a.size(); std::vector res(n, std::vector<bool>(n)); for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { res[i][j] = Query(a[i], a[j]); res[j][i] = !res[i][j]; } } std::vector<std::pair<int, int>> v; for (int i = 0; i < n; i++) v.emplace_back(std::accumulate(res[i].begin(), res[i].end(), 0), a[i]); std::sort(v.begin(), v.end()); for (int i = 0; i < n; i++) { a[i] = v[i].second; } if (Query(a[1], a[0])) std::swap(a[1], a[0]); if (Query(a[n - 1], a[n - 2])) std::swap(a[n - 1], a[n - 2]); return a; } } // namespace std::vector<int> Solve(int n) { std::vector<int> a(n); std::iota(a.begin(), a.end(), 0); a = sort(a); std::vector<int> s(a.begin(), a.begin() + std::min(n, 10)); s = slow(s); int x = s[0]; a.erase(std::find(a.begin(), a.end(), x)); a.insert(a.begin(), x); for (int i = 1; i < n; i++) { int j = i; while (j < n && Query(a[j], x)) j++; std::reverse(a.begin() + i, a.begin() + std::min(j + 1, n)); i = j; x = a[i]; } std::vector<int> ans(n); for (int i = 0; i < n; i++) { ans[a[i]] = i; } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...