Submission #414021

#TimeUsernameProblemLanguageResultExecution timeMemory
414021cfalasCounting Mushrooms (IOI20_mushrooms)C++14
80.71 / 100
15 ms360 KiB
#include "mushrooms.h" #include<bits/stdc++.h> using namespace std; #define mp make_pair #define INF 10000000 #define MOD 1000000007 #define MID ((l+r)/2) #define HASHMOD 2305843009213693951 #define ll long long #define ull unsigned long long #define F first #define S second typedef pair<ll, ll> ii; typedef pair<ii, int> iii; typedef vector<int> vi; typedef vector<ii> vii; typedef map<int, int> mii; #define EPS 1e-6 #define FOR(i,n) for(int i=0;i<((int)(n));i++) #define FORi(i,a,b) for(int i=((int)(a));i<((int)(b));i++) #define FOA(v, a) for(auto v : a) int count_mushrooms(int n) { int ans=1; vi a; vi b; a.push_back(0); int last=0; FORi(i,1,min(n, 3)){ if(a.size()>=2 || b.size()>=2) break; int x = use_machine({0,i}); if(x) b.push_back(i); else a.push_back(i), ans++; last = i; } vi c; FORi(i,last+1,n){ if(a.size()>=b.size()) c = a; else c = b; vi m; FOR(j,c.size()){ if(i+j>=n) break; m.push_back(c[j]), m.push_back(i+j); } int u = m.size()/2; int x = use_machine(m); if(a.size()==c.size()) ans+=u - (x+1)/2; else ans+=(x+1)/2; i+=u-1; if(a.size()>=b.size() && x%2==0) a.push_back(i); else if(a.size()>=b.size() && x%2==1) b.push_back(i); else if(a.size()<b.size() && x%2==1) a.push_back(i); else if(a.size()<b.size() && x%2==0) b.push_back(i); } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...