# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
430552 | alishahali1382 | Counting Mushrooms (IOI20_mushrooms) | C++14 | 14 ms | 456 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>
#pragma GCC optimize("O2")
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
#define debug(x) {cerr<<#x<<"="<<x<<"\n";}
#define debug2(x, y) {cerr<<"{"<<#x<<", "<<#y<<"}={"<<x<<", "<<y<<"}\n";}
#define debugp(p) {cerr<<#p<<"={"<<p.first<<", "<<p.second<<"}\n";}
#define debugv(abcd) {cerr<<#abcd<<": "; for (auto dcba:abcd) cerr<<dcba<<", ";cerr<<"\n";}
#define pb push_back
#define all(x) x.begin(), x.end()
#define SZ(x) ((int)x.size())
const int inf=1000000100; // 1e9
const ll INF=10000000001000000; // 1e16
const int mod=1000000007;
const int MAXN=20010;
int n, m, k, x, y, a, b, t=80, ans;
vi A, B;
inline int ask(vi vec){ return use_machine(vec);}
int Solve(vi vec){
if (SZ(A)>=SZ(vec)){
vi shit;
for (int i=0; i<SZ(vec); i++){
shit.pb(A[i]);
shit.pb(vec[i]);
}
// shit.pb(A[SZ(vec)]);
int res=ask(shit);
if (res&1) B.pb(shit.back());
else A.pb(shit.back());
return SZ(vec)-(res+1)/2;
}
vi shit;
for (int i=0; i<SZ(vec); i++){
shit.pb(B[i]);
shit.pb(vec[i]);
}
// shit.pb(B[SZ(vec)]);
int res=ask(shit);
if (res&1) A.pb(shit.back());
else B.pb(shit.back());
return (res+1)/2;
}
int count_mushrooms(int _n){
n=_n;
if (n<400){ // wtf am I doing?
ans=1;
for (int i=1; i<n; i+=2){
if (i==n-1){
ans+=1-ask({0, i});
continue ;
}
ans+=2-ask({i, 0, i+1});
}
return ans;
}
int pos=0;
bool rev=0;
A.pb(pos++);
while (pos<3){
int i=pos++;
if (ask({0, i})) B.pb(i);
else A.pb(i);
}
if (SZ(A)<2){
A.swap(B);
rev=1;
}
assert(SZ(A)>=2);
for (int i=pos; max(SZ(A), SZ(B))<t; i+=2, pos+=2){
int tmp=ask({i, A[0], i+1, A[1]});
if (tmp&1) B.pb(i);
else A.pb(i);
if (tmp&2) B.pb(i+1);
else A.pb(i+1);
}
if (rev) A.swap(B);
// assert(max(SZ(A), SZ(B))>=t);
ans=SZ(A);
for (int i=pos; i<n; ){
vi vec;
while(SZ(vec)<max(SZ(A), SZ(B)) && i<n)
vec.pb(i++);
// debugv(vec)
ans+=Solve(vec);
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |