Submission #390867

#TimeUsernameProblemLanguageResultExecution timeMemory
390867AlexPop28Counting Mushrooms (IOI20_mushrooms)C++14
0 / 100
2 ms204 KiB
#include "mushrooms.h" #include <bits/stdc++.h> using namespace std; #ifdef LOCAL_DEFINE const int K = 2; #else const int K = 141; #endif mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int count_mushrooms(int n) { if (n <= K) { int ans = 0; for (int i = 1; i < n; ++i) { vector<int> curr = {0, i}; ans += use_machine(curr); } return n - ans; } vector<int> val(n, -1); val[0] = 0; auto Get = [&]() { int pos = rng() % n; while (val[pos] >= 0) pos = rng() % n; return pos; }; vector<int> pos_a, pos_b; auto A = [&](int x) { assert(val[x] == -1); pos_a.emplace_back(x); val[x] = 0; }; auto B = [&](int x) { assert(val[x] == -1); pos_b.emplace_back(x); val[x] = 1; }; while((int)max(pos_a.size(), pos_b.size()) < 2) { int pos = Get(); vector<int> curr = {0, pos}; if (use_machine(curr) == 0) { A(pos); } else { B(pos); } } if (pos_a.size() > pos_b.size()) { // am 2 A while((int)max(pos_a.size(), pos_b.size()) < K) { int pos0 = Get(), pos1 = Get(); vector<int> curr = {pos_a[0], pos0, pos_a[1], pos1}; int val = use_machine(curr); if (val == 0) { A(pos0); A(pos1); } else if (val == 1) { A(pos0); B(pos1); } else if (val == 2) { B(pos0); A(pos1); } else { B(pos0); B(pos1); } } } else { // am 2 B while((int)max(pos_a.size(), pos_b.size()) < K) { int pos0 = Get(), pos1 = Get(); vector<int> curr = {pos_b[0], pos0, pos_b[1], pos1}; int val = use_machine(curr); if (val == 0) { B(pos0); B(pos1); } else if (val == 1) { B(pos0); A(pos1); } else if (val == 2) { A(pos0); B(pos1); } else { A(pos0); A(pos1); } } } bool type = false; auto pos = pos_a; if (pos_b.size() > pos_a.size()) { type = true; pos = pos_b; } int ans = pos_a.size() + 1; int i = 0; auto Fix = [&]() { while (i < n && val[i] >= 0) ++i; }; Fix(); while (i < n) { vector<int> curr; for (int j = 0; j < K; ++j) { curr.emplace_back(pos[j]); if (i == n) break; if (j + 1 < K) curr.emplace_back(i++); Fix(); } int total = (curr.size() - 1) / 2; int ret = use_machine(curr) / 2; if (!type) ret = total - ret; ans += ret; Fix(); } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...