# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
303752 | aljasdlas | Counting Mushrooms (IOI20_mushrooms) | C++14 | 14 ms | 584 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;
int count_mushrooms(int n) {
if(n < 220) {
int B = 0;
for(int i = 1; i < n; i++) {
B += use_machine({0, i});
}
return n-B;
}
vector<int> perm;
for(int i = 1; i < n; i++)
perm.push_back(i);
srand(time(0));
random_shuffle(perm.begin(), perm.end());
reverse(perm.begin(), perm.end());
perm.push_back(0);
reverse(perm.begin(), perm.end());
vector<int> A, B;
A = {0};
if(use_machine({0,perm[1]})) B.push_back(perm[1]);
else A.push_back(perm[1]);
if(use_machine({0,perm[2]})) B.push_back(perm[2]);
else A.push_back(perm[2]);
if(B.size() > A.size()) swap(A,B);
for(int i = 3; i < n && A.size()*A.size() < (n-A.size()-B.size()) && B.size()*B.size() < (n-A.size()-B.size()); i+=2) {
vector<int> cur;
cur.push_back(A[0]);
cur.push_back(perm[i]);
cur.push_back(A[1]);
if(i+1 < n) cur.push_back(perm[i+1]);
// for(auto x: cur) cerr << x << " ";
// cerr << endl;
int res = use_machine(cur);
if(res & 2) B.push_back(perm[i]);
else A.push_back(perm[i]);
if(i+1 < n) {
if(res & 1) B.push_back(perm[i+1]);
else A.push_back(perm[i+1]);
}
}
if(B.size() > A.size()) swap(A,B);
int countA = 0;
int countB = 0;
for(int i = A.size()+B.size(); i < n; i+=A.size()) {
vector<int> cur;
int j = 0;
for(j = 0; i+j < n && j < A.size(); j++) {
cur.push_back(A[j]);
cur.push_back(perm[i+j]);
}
// for(auto x: cur) cerr << x << " ";
// cerr << ": ";
int res = use_machine(cur);
countB += (res+1)/2;
countA += j - ((res+1)/2);
// cerr << res << " -> " << countA << " " << countA << endl;;
}
if(A[0] == 0) return A.size()+countA;
else return B.size()+countB;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |