Submission #759945

#TimeUsernameProblemLanguageResultExecution timeMemory
759945raysh07Counting Mushrooms (IOI20_mushrooms)C++17
80.71 / 100
7 ms484 KiB
#include "mushrooms.h" #include <bits/stdc++.h> using namespace std; // const int N = 101; // int ac[N]; // int use_machine(vector <int> a){ // int ans = 0; // for (int i = 1; i < a.size(); i++){ // ans += ac[a[i]] != ac[a[i - 1]]; // } // return ans; // } int count_mushrooms(int n) { vector <int> a, b; a.push_back(0); int p = 1; int ans = 0; while (p < n){ // cout << "PRINTING " << p << " "; // for (auto x : a) cout << x << " "; // cout << "\n"; if (a.size() > b.size()){ int g = a.size(); g = min(g, n - p); vector <int> m; for (int i = 0; i < g; i++){ m.push_back(p + i); m.push_back(a[i]); } int c = use_machine(m); if (c & 1) b.push_back(p), c--; else a.push_back(p); // cout << g << " " << c/2 << "\n"; ans += g - 1 - (c/2); p += g; } else { int g = b.size(); g = min(g, n - p); vector <int> m; for (int i = 0; i < g; i++){ m.push_back(p + i); m.push_back(b[i]); } int c = use_machine(m); if (c & 1) a.push_back(p), c--; else b.push_back(p); ans += c/2; p += g; } } return ans + a.size(); } // int main(){ // int n; cin >> n; // for (int i = 0; i < n; i++) cin >> ac[i]; // cout << count_mushrooms(n) << "\n"; // return 0; // }
#Verdict Execution timeMemoryGrader output
Fetching results...