# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
831240 | Username4132 | Counting Mushrooms (IOI20_mushrooms) | C++17 | 7 ms | 312 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"
#include<iostream>
#include<vector>
using namespace std;
#define forn(i, n) for(int i=0; i<(int)n; ++i)
#define forsn(i, s, n) for(int i=s; i<(int)n; ++i)
#define PB push_back
const int SZ = 135;
int count_mushrooms(int n) {
if(n==2) return use_machine({0, 1}) + 1;
int a, b, f, s, type, pen = min(2*SZ + 3, n);
a = use_machine({0, 1});
b = use_machine({0, 2});
if(a==0) f=0, s=1, type=0;
else if(b==0) f=0, s=2, type=0;
else f=1, s=2, type=1;
vector<bool> res(pen);
res[0]=0, res[1]=a, res[2]=b;
for(int i=3; i<pen; i+=2){
if(i+1<pen){
int ret = use_machine({f, i, s, i+1});
res[i]=(ret>>1)^type, res[i+1]=(ret&1)^type;
}
else{
int ret = use_machine({f, i, s});
res[i]=(ret>>1)^type;
}
}
int tot=0, ans=0;
vector<int> toUse;
forn(i, pen) tot+=res[i];
bool cond = 2*tot > pen;
forn(i, pen) if(res[i] == cond) toUse.PB(i);
forn(i, pen) ans+=!res[i];
int sz = (int)toUse.size(), l=pen;
while(l<n){
vector<int> ask;
int r = min(l+sz, n);
forn(i, r-l){
ask.PB(toUse[i]);
ask.PB(l+i);
}
int ret = use_machine(ask);
int ad = ((ret+1)>>1);
ans+=(cond? ad : r-l-ad);
l=r;
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |