Submission #1052441

#TimeUsernameProblemLanguageResultExecution timeMemory
1052441aykhnCounting Mushrooms (IOI20_mushrooms)C++17
80.71 / 100
6 ms784 KiB
#include "mushrooms.h" #include <bits/stdc++.h> using namespace std; int B = 137; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int count_mushrooms(int n) { vector<int> v[2]; vector<int> o(n); iota(o.begin(), o.end(), 0); shuffle(o.begin() + 1, o.end(), rng); v[0] = {0}; int res = 0; for (int j = 1; j < n;) { vector<int> q; int l = j, r = min(n, j + (int)max(v[0].size(), v[1].size())); int sz = r - l; for (int k = l; k < r; k++) { if (v[0].size() > v[1].size()) { q.push_back(v[0][k - l]); q.push_back(o[k]); } else { q.push_back(v[1][k - l]); q.push_back(o[k]); } } if (v[0].size() > v[1].size()) { int x = use_machine(q); res += sz - ((x + 1) / 2); if (x & 1) v[1].push_back(o[r - 1]); else v[0].push_back(o[r - 1]), res--; } else { int x = use_machine(q); res += (x + 1) / 2; if (x & 1) v[0].push_back(o[r - 1]), res--; else v[1].push_back(o[r - 1]); } j = r; } return res + v[0].size(); }
#Verdict Execution timeMemoryGrader output
Fetching results...