Submission #797847

#TimeUsernameProblemLanguageResultExecution timeMemory
797847boyliguanhanCounting Mushrooms (IOI20_mushrooms)C++17
91.87 / 100
7 ms336 KiB
#include "mushrooms.h" #include<bits/stdc++.h> using namespace std; #define X 101 int count_mushrooms(int n) { if(n<400) { int ans = 0; n--; for(int i = 1; i <= n/2;i++) ans+=use_machine({i*2-1,0,i*2}); if(n%2) ans+=use_machine({0,n}); return n+1-ans; } vector<int> good{0}; vector<int> other; int second = 0; if(!use_machine({0,1})) second = 1, good.push_back(1); else other.push_back(1); if(!use_machine({0,2})) second = 1, good.push_back(2); else other.push_back(2); if(!second) swap(good, other); for(int i = 3; i < 2*X-1; i+=2) { int res = use_machine({i,good[0],i+1,good[1]}); if(res%2-1) good.push_back(i); else other.push_back(i); if(res<2) good.push_back(i+1); else other.push_back(i+1); } if(good.size()<other.size()) second=!second, swap(good, other); int ans = 0, num = 0; for(int i = 2*X-1; i < n;) { int r = min(n, i+(int)good.size()); num+=r-i-1; vector<int> v; for(int j = i; j < r; j++) { v.push_back(j); v.push_back(good[j-i]); } int x = use_machine(v); ans+=r-i-1-x/2; int sz = good.size(); if(x%2) other.push_back(i); else good.push_back(i); i+=sz; if(good.size()<other.size()) second=!second, swap(good, other), ans = num-ans; } ans+=good.size(); if(second) return ans; return n - ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...