Submission #609880

#TimeUsernameProblemLanguageResultExecution timeMemory
609880KoDCounting Mushrooms (IOI20_mushrooms)C++17
25 / 100
94 ms248 KiB
#include "mushrooms.h" #include <bits/stdc++.h> using std::array; using std::pair; using std::tuple; using std::vector; constexpr int K = 3; int count_mushrooms(int n) { vector<char> color(n); array<vector<int>, 2> list = {}; list[0].push_back(0); int k = 1; while (k < n and (int)std::max(list[0].size(), list[1].size()) < K) { if (k + 1 == n or (list[0].size() <= 1 and list[1].size() <= 1)) { color[k] = use_machine({0, k}); list[color[k]].push_back(k); k += 1; } else { if (list[0].size() >= 2) { const int tmp = use_machine({list[0][0], k, list[0][1], k + 1}); color[k] = tmp / 2; color[k + 1] = tmp % 2; } else { const int tmp = use_machine({list[1][0], k, list[1][1], k + 1}); color[k] = 1 - tmp / 2; color[k + 1] = 1 - tmp % 2; } list[color[k]].push_back(k); list[color[k + 1]].push_back(k + 1); k += 2; } } const int fixed = (int)list[0].size() >= K ? 0 : 1; int ret = std::count(color.begin(), color.begin() + k, 0); while (k < n) { const int l = k; const int r = std::min(n, k + K); k = r; vector<int> vec; for (int i = l; i < r; ++i) { vec.push_back(list[fixed][i - l]); vec.push_back(i); } const int cnt = (use_machine(vec) + 1) / 2; if (fixed == 0) { ret += (r - l) - cnt; } else { ret += cnt; } } return ret; }
#Verdict Execution timeMemoryGrader output
Fetching results...