Submission #429782

#TimeUsernameProblemLanguageResultExecution timeMemory
429782MarcoMeijerCounting Mushrooms (IOI20_mushrooms)C++14
55.80 / 100
16 ms460 KiB
#include "mushrooms.h" #include <bits/stdc++.h> using namespace std; // macros typedef long long ll; typedef long double ld; typedef pair<int, int> ii; typedef pair<ll, ll> lll; typedef tuple<int, int, int> iii; typedef vector<int> vi; typedef vector<ii> vii; typedef vector<iii> viii; typedef vector<ll> vll; typedef vector<lll> vlll; #define REP(a,b,c) for(int a=int(b); a<int(c); a++) #define RE(a,c) REP(a,0,c) #define RE1(a,c) REP(a,1,c+1) #define REI(a,b,c) REP(a,b,c+1) #define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--) #define FOR(a,b) for(auto& a : b) #define all(a) a.begin(), a.end() #define INF 1e9 #define EPS 1e-9 #define pb push_back #define popb pop_back #define fi first #define se second #define sz size() mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); // output template<class T1, class T2> void OUT(const pair<T1,T2>& x); template<class T> void OUT(const vector<T>& x); template<class T> void OUT(const T& x) {cout << x;} template<class H, class... T> void OUT(const H& h, const T&... t) {OUT(h); OUT(t...); } template<class T1, class T2> void OUT(const pair<T1,T2>& x) {OUT(x.fi,' ',x.se);} template<class T> void OUT(const vector<T>& x) {RE(i,x.size()) OUT(i==0?"":" ",x[i]);} template<class... T> void OUTL(const T&... t) {OUT(t..., "\n"); } template<class H> void OUTLS(const H& h) {OUTL(h); } template<class H, class... T> void OUTLS(const H& h, const T&... t) {OUT(h,' '); OUTLS(t...); } const int SQ = 120; int count_mushrooms(int n) { vi a, b; a.pb(0); int cntA=1, cntB=0; bool swapped = 0; auto switchAB = [&]() { swap(cntA,cntB); swap(a,b); swapped = !swapped; }; vi next; REP(i,1,n) next.pb(i); while(a.size() < SQ && b.size() < SQ) { if(next.empty()) break; vi m; m.pb(a.back()); m.pb(next.back()); next.pop_back(); int res = use_machine(m); (res ? b : a).pb(m.back()); (res ? cntB : cntA)++; } if(b.size() > a.size()) switchAB(); while(!next.empty()) { vi m; vi ca = a; int total = 0; RE(i,a.size()-1) { if(next.empty()) break; m.pb(ca.back()); ca.pop_back(); m.pb(next.back()); next.pop_back(); total++; } m.pb(ca.back()); ca.pop_back(); int res = use_machine(m); cntB += res/2; cntA += total - res/2; } if(swapped) switchAB(); return cntA; }
#Verdict Execution timeMemoryGrader output
Fetching results...