Submission #1240039

#TimeUsernameProblemLanguageResultExecution timeMemory
1240039SalihSahinCounting Mushrooms (IOI20_mushrooms)C++20
0 / 100
1 ms432 KiB
#include "bits/stdc++.h" #include "mushrooms.h" using namespace std; int count_mushrooms(int n) { if(n <= 225){ int cnt = 1; vector<int> v; v.push_back(0); for(int j = 1; j < n; j++){ v.push_back(j); int x = use_machine(v); if(!x) cnt++; v.pop_back(); } return cnt; } vector<int> type[2]; type[0].push_back(0); vector<int> v; v.push_back(0); int ind = 1; while(ind < n){ v.push_back(ind); int x = use_machine(v); type[x].push_back(ind); v.pop_back(); ind++; if(max(type[0].size(), type[1].size()) >= 2){ break; } } int X = 150; if(type[0].size() >= 2){ while(ind + 1 < n){ if(max(type[0].size(), type[1].size()) >= X) break; vector<int> v = {0, ind, type[0][1], ind + 1}; int x = use_machine(v); type[((x&2) > 0)].push_back(ind); type[x&1].push_back(ind+1); ind += 2; } } else{ while(ind + 1 < n){ if(max(type[0].size(), type[1].size()) >= X) break; vector<int> v = {type[1][0], ind, type[1][1], ind + 1}; int x = use_machine(v); type[!((x&2) > 0)].push_back(ind); type[!(x&1)].push_back(ind+1); ind += 2; } } int ans = type[0].size(); while(ind < n){ vector<int> query; if(type[0].size() > type[1].size()){ for(int i = 0; i < type[0].size(); i++){ query.push_back(type[0][i]); if(ind < n){ query.push_back(ind); ind++; } } int val = use_machine(query); if(val&1) type[1].push_back(ind-1); ans += (query.size() - (val + (val&1))) / 2; } else{ for(int i = 0; i < type[1].size(); i++){ query.push_back(type[1][i]); if(ind < n){ query.push_back(ind); ind++; } } int val = use_machine(query); if(val&1) type[0].push_back(ind-1); ans += ((val + (val&1)) / 2); } } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...