# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
367656 | rocks03 | Counting Mushrooms (IOI20_mushrooms) | C++14 | 11 ms | 512 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.
//#pragma GCC target("avx2")
//#pragma GCC optimization("O3")
//#pragma GCC optimization("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define pb push_back
#define SZ(x) ((int)(x).size())
#define all(x) x.begin(), x.end()
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define per(i, a, b) for(int i = (a); i >= (b); i--)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int use_machine(vector<int>);
int count_mushrooms(int N){
vector<int> a = {0}, b;
int ind = 1;
vector<int> ask = {0, 1};
int ans = use_machine(ask);
++ind;
if(ans == 0) a.pb(1);
else b.pb(1);
if(N == 2) return SZ(a);
if(SZ(a) < 2){
ask = {0, 2};
ans = use_machine(ask);
if(ans == 1) b.pb(2);
else a.pb(2);
++ind;
}
const int BOUND = 104;
while(ind + 1 <= N - 1 && max(SZ(a), SZ(b)) < BOUND){
if(SZ(a) >= SZ(b)){
ask = {ind, a[0], ind + 1, a[1]};
ans = use_machine(ask);
if(ans == 0){
a.pb(ind); a.pb(ind + 1);
} else if(ans == 1){
b.pb(ind); a.pb(ind + 1);
} else if(ans == 2){
a.pb(ind); b.pb(ind + 1);
} else if(ans == 3){
b.pb(ind); b.pb(ind + 1);
}
ind += 2;
} else{
ask = {ind, b[0], ind + 1, b[1]};
ans = use_machine(ask);
if(ans == 0){
b.pb(ind); b.pb(ind + 1);
} else if(ans == 1){
a.pb(ind); b.pb(ind + 1);
} else if(ans == 2){
b.pb(ind); a.pb(ind + 1);
} else if(ans == 3){
a.pb(ind); a.pb(ind + 1);
}
ind += 2;
}
}
if(ind == N) return SZ(a);
if(ind + 1 == N){
ask = {0, N - 1};
ans = use_machine(ask);
if(ans == 1) b.pb(N - 1);
else a.pb(N - 1);
++ind;
return SZ(a);
}
int answer = SZ(a);
while(ind <= N - 1){
if(SZ(a) >= SZ(b)){
ask.clear();
rep(i, 0, SZ(a)){
if(ind > N - 1) break;
ask.pb(a[i]);
ask.pb(ind);
++ind;
}
ans = use_machine(ask);
answer += SZ(ask) / 2 - (ans + 1) / 2;
if(ans & 1){
b.pb(ask.back());
} else{
a.pb(ask.back());
}
} else{
ask.clear();
rep(i, 0, SZ(b)){
if(ind > N - 1) break;
ask.pb(b[i]);
ask.pb(ind);
++ind;
}
ans = use_machine(ask);
answer += (ans + 1) / 2;
if(ans & 1){
a.pb(ask.back());
} else{
b.pb(ask.back());
}
}
}
return answer;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |