Submission #354275

#TimeUsernameProblemLanguageResultExecution timeMemory
354275amunduzbaevCounting Mushrooms (IOI20_mushrooms)C++14
0 / 100
0 ms364 KiB
#include "mushrooms.h" #ifndef EVAL #include "stub.cpp" #endif #include <bits/stdc++.h> using namespace std; #define ff first #define ss second #define pb push_back #define mp make_pair #define ub upper_bound #define lb lower_bound #define ll long long #define ld long double #define pii pair<int, int> #define pll pair<ll, ll> #define sz(x) (int)x.size() #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(),x.rend() #define fastios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define vll vector<ll> #define vii vector<int> #define vpii vector<pii> #define vpll vector<pll> #define cnt(a)__builtin_popcount(a) template<class T> bool umin(T& a, const T& b) {return a > b? a = b, true:false;} template<class T> bool umax(T& a, const T& b) {return a < b? a = b, true:false;} const int N = 2e3+5; const int mod = 1e9+7; const ll inf = 1e18; const ld Pi = acos(-1); vector<int> a, b; int i; void find(){ i = 1; while(sz(a) < 2 && sz(b) < 2){ vii tt = {0, i}; if(!use_machine(tt)) a.pb(i); else b.pb(i); i++; } if(sz(a) == 2){ while(sz(a) < 140 && sz(b) < 140){ vii tt = {0, i, a[0], i+1}; int res = use_machine(tt); if(res == 0){ a.pb(i); a.pb(i+1); }if(res == 1){ a.pb(i); b.pb(i+1); }if(res == 2){ a.pb(i+1); b.pb(i); }if(res == 3){ b.pb(i+1); b.pb(i); }i+=2; } }else{ while(sz(a) < 140 && sz(b) < 140){ vii tt = {b[0], i, b[1], i+1}; int res = use_machine(tt); if(res == 0){ b.pb(i); b.pb(i+1); }if(res == 1){ b.pb(i); a.pb(i+1); }if(res == 2){ b.pb(i+1); a.pb(i); }if(res == 3){ a.pb(i+1); a.pb(i); }i+=2; } } //cout<<"A\n"; //for(auto x:a) cout<<x<<" "; //cout<<"\nB\n"; //for(auto x:b) cout<<x<<" "; //cout<<"\n___\n"; } int count_mushrooms(int n){ if(i < 300){ int ans = 1; for(int i=1;i<n;i++){ vii tmp = {0, 1}; if(!use_machine(tmp))ans++; }return ans; } find(); int ans = 0; for(;i<n;){ if(sz(a) > sz(b)){ vii tmp; int cnt = 0; for(auto x:a){ tmp.pb(x); tmp.pb(i); i++, cnt++; if(i >= n) break; } //for(auto x:tmp) cout<<x<<" "; //cout<<"\n"; int res = use_machine(tmp); if(res%2)b.pb(i-1); else a.pb(i-1); res /= 2; ans += (cnt - res); }else{ vii tmp; for(auto x:b){ tmp.pb(x); tmp.pb(i); i++; if(i >= n) break; } //for(auto x:tmp) cout<<x<<" "; //cout<<"\n"; int res = use_machine(tmp); if(res%2)a.pb(i-1); else b.pb(i-1); res /= 2; ans += res; } } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...