Submission #414041

#TimeUsernameProblemLanguageResultExecution timeMemory
414041cfalasCounting Mushrooms (IOI20_mushrooms)C++14
92.24 / 100
11 ms432 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) #define BLOCK 90 int count_mushrooms(int n) { int ans=1; vi a; vi b; a.push_back(0); int last=0; FORi(i,1,n){ if(a.size()>=BLOCK || b.size()>=BLOCK) break; if((a.size()<2 && b.size()<2) || i+1>=n){ int x = use_machine({0,i}); if(x) b.push_back(i); else a.push_back(i), ans++; } else{ vi c; if(a.size()>=2) c = a; else c = b; int x = use_machine({c[0], i, c[1], i+1}); int cur=0; if(a.size()<2) x = 3-x; if(x==0) a.push_back(i), a.push_back(i+1), cur+=2; else if(x==1) a.push_back(i), b.push_back(i+1), cur++; else if(x==2) b.push_back(i), a.push_back(i+1), cur++; else if(x==3) b.push_back(i), b.push_back(i+1); ans+=cur; i++; } 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...