# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1047475 | nightfal | Counting Mushrooms (IOI20_mushrooms) | C++17 | 1 ms | 420 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 <vector>
#include <iostream>
#include <tuple>
using namespace std;
int use_machine(std::vector<int> x);
int count2(vector<int> &a, vector<int> &b, int &now, int n, int letter) {
vector<int> m;
int numA=0, numB=0;
for(int i=0; i<a.size() && now < n; i++, now++) {
m.push_back(a[i]);
m.push_back(now);
}
int result = use_machine(m);
if (result%2) numB++;
else numA++;
numB += result/2;
numA += m.size()/2-1-result/2;
if (letter) return numA;
else return numB;
}
void count1(vector<int> &a, vector<int> &b, int num, int n) {
int k = min(num,n);
for(int i=3; i+1<k; i+=2) {
int result = use_machine({a[0],i,a[1],i+1});
if (result%2) b.push_back(i+1);
else a.push_back(i+1);
if (result/2) b.push_back(i);
else a.push_back(i);
}
if (k%2==0) {
if(use_machine({a[0],k-1})) b.push_back(k-1);
else a.push_back(k-1);
}
return;
}
int count_mushrooms(int n) {
vector<int>a, b; a.push_back(0);
int numA=0, number1=100;
for(int i=1; i<min(3,n); i++)
if (use_machine({0,i})) b.push_back(i);
else a.push_back(i);
if (n<=3) return a.size();
if(a.size()>=b.size()) count1(a,b,number1,n);
else count1(b,a,number1,n);
if (n<=number1) return a.size();
numA = a.size();
while (number1 < n) {
if(a.size()>=b.size()) numA += count2(a,b,number1,n,0);
else numA += count2(b,a,number1,n,1);
}
return numA;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |