# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1079783 | HD1 | Counting Mushrooms (IOI20_mushrooms) | C++14 | 8 ms | 600 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 <vector>
#include <iostream>
using namespace std;
int count_mushrooms(int n) {
if(n < 100){
int res = 1;
for(int i = 2; i <= n;i++){
int ans = use_machine({0,i-1});
res += 1 - ans;
}
return res;
}
int k = -1,mini = 1e9;
for(int i = 1; i < n; i++){
int v = 2*i + ( n - (2*i + 1 ) +i)/(i+1);
if(mini > v) mini = v, k = i;
}
vector<int> A,B;
A.push_back(1);
for(int i = 2; i <= 2*k + 1;i++){
int ans = use_machine({0,i-1});
if(ans == 0) A.push_back(i);
else B.push_back(i);
}
// cout << k << endl;
bool isA = true;
int res = A.size();
if(B.size() > A.size()) swap(A,B), isA = false;
for(int i = 1; i <= ( n - (2*k + 1 ) +k)/(k+1); i++){
int ini = 2*k+2 + (i-1)*(k+1) ;
int fin = min(n+1, 2*k+2 + (i)*(k+1));
vector<int> q;
// cout << ini << " " << fin << endl;
for(int j = ini; j < fin; j++){
q.push_back(j-1);
q.push_back(A[j-ini]-1);
}
int ans = use_machine(q);
if(ans&1) ans = 1 + ans/2;
else ans = ans/2;
res += ( isA ? fin-ini-ans : ans);
//cout << "RES: "<< res << " " << ans << endl;
}
// A A B A B A -> 5 -> 2
// B A A A A A -> 1 -> 1 + 1/1
// p A p A p A -> x -> x/2 -
// -> 1 + x/2
// cout << res << endl;
// 1 query tenemos que un valr i -> i+1 tipos -> 2*i -> i+1 del mismo tipo
// n/(i+2)
return res;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |