# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
602121 | definitelynotmee | Counting Mushrooms (IOI20_mushrooms) | C++17 | 10 ms | 440 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<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T>
using matrix = vector<vector<T>>;
const int initial =165;
int count_mushrooms(int n) {
if(n <= 3){
int resp = 1;
for(int i = 1; i < n; i++)
resp+=use_machine({0,i})^1;
return resp;
}
vector<int> start(initial,-1);
start[0] = 1;
start[1] = use_machine({0,1})^1;
start[2] = use_machine({0,2})^1;
int q1 = 0, q2 = 1, qresp = 1;
if(start[1] != 1){
if(start[2] != 1){
q1 = 1, q2 = 2, qresp = 0;
} else q2 = 2;
}
for(int i = 3; i+1 < min(initial,n); i+=2){
int ret = use_machine({q1,i+1,q2,i});
for(int j = 0; j < 2; j++){
if((1<<j)&ret)
start[i+j] = qresp^1;
else start[i+j] = qresp;
}
}
if(start[min(initial,n)-1] == -1){
start[min(initial,n)-1] = use_machine({0,min(initial,n)-1})^1;
}
int resp = 0;
array<vector<int>,2> mush;
for(int i = 0; i < min(initial,n); i++){
//cout << start[i] << ' ';
resp+=start[i];
mush[start[i]].push_back(i);
}
//cout << '\n';
int id = initial;
while(id < n){
int type = mush[0].size() > mush[1].size() ? 0 : 1;
vector<int> query;
int ptr = 0, ct = 0;
while(id < n && ptr < mush[type].size()){
query.push_back(mush[type][ptr]);
query.push_back(id);
ptr++;
id++;
ct++;
}
int ret = use_machine(query);
resp+=type ? ct-(ret+1)/2 : (ret+1)/2;
if(ret&1)
mush[type^1].push_back(id-1);
else mush[type].push_back(id-1);
}
return resp;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |