# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
423220 | xyz | Counting Mushrooms (IOI20_mushrooms) | C++17 | 1 ms | 200 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 <bits/stdc++.h>
#include "mushrooms.h"
using namespace std;
typedef long long ll;
int m = 2;
int count_mushrooms(int n){
vector<int> A, B;
A = {0};
int go = 2 * m + 5;
for(int i = 1; i < min(n, go); i ++){
vector<int> ask = {0, i};
int x = use_machine(ask);
if(!x)
A.push_back(i);
else
B.push_back(i);
}
int result = A.size(), pos = go;
while(pos < n){
m = max((int)A.size(), (int)B.size()) - 1;
if(A.size() >= B.size()){
vector<int> ask;
if(pos + m < n)
ask.push_back(pos + m);
ask.push_back(A[0]);
int cur = 1;
for(int j = pos; j < min(n, pos + m); j ++){
ask.push_back(j);
ask.push_back(A[cur]);
++ cur;
}
// cout << "-query1" << endl;
// cout << ask.size() << endl;
// for(int e : ask)
// cout << e << " ";
// cout << endl;
int x = use_machine(ask), y = ask.size();
if(pos + m < n){
-- y;
if(x % 2 == 1){
B.push_back(pos + m);
-- x;
}else{
A.push_back(pos + m);
}
}
result += ((y - 1) - x) / 2;
pos += m + 1;
}else{
vector<int> ask;
if(pos + m < n)
ask.push_back(pos + m);
ask.push_back(B[0]);
int cur = 1;
for(int j = pos; j < min(n, pos + m); j ++){
ask.push_back(j);
ask.push_back(B[cur]);
++ cur;
}
// cout << "-query2" << endl;
int x = use_machine(ask);
if(pos + m < n){
if(x % 2 == 1){
A.push_back(pos + m);
-- x;
}else{
B.push_back(pos + m);
}
}
result += x / 2;
pos += m + 1;
}
}
return result;
}
//15
//0 1 0 1 0 1 0 1 0 1 0 1 0 1 0
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |