# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
354452 | amunduzbaev | Counting Mushrooms (IOI20_mushrooms) | C++14 | 1 ms | 384 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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, B = 143, nn;
void find(){
i = 1;
a.pb(0);
while(sz(a) < 2 && sz(b) < 2 && i < nn){
if(!use_machine({0, i})) a.pb(i);
else b.pb(i);
i++;
}
if(sz(a) > sz(b)){
while(sz(a) < B && sz(b) < B && i + 1 < nn){
vii tt = {a[0], i, a[1], 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) < B && sz(b) < B && i + 1 < nn){
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"<<endl;
//for(auto x:a) cout<<x<<" ";
//cout<<endl<<"____________________________________"<<endl;
//cout<<endl<<"B"<<endl;
//for(auto x:b) cout<<x<<" ";
//cout<<endl<<"____________________________________"<<endl;
}
int count_mushrooms(int n){
nn = n;
find();
//if(i == n-1){
//if(!use_machine({0, i})) a.pb(i);
//else b.pb(i);
//i++;
//}
int ans = sz(a);
//cout<<ans<<"\n";
//cout<<sz(b)<<"\n";
while(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;
}
int res = use_machine(tmp);
if(res % 2) b.pb(i-1);
else a.pb(i-1);
cnt--, res--, res /= 2;
ans += (cnt - res);
}
else{
vii tmp;
for(auto x:b){
tmp.pb(x);
tmp.pb(i);
i++;
if(i >= n) break;
}
int res = use_machine(tmp);
if(res % 2) a.pb(i-1);
else b.pb(i-1);
res--, res /= 2;
ans += res;
}
//cout<<ans<<"\n";
//cout<<sz(b)<<"\n";
//if(i == n-1){
//if(!use_machine({0, i})) { a.pb(i); ans++; }
//else b.pb(i);
//i++;
//}
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |