Submission #885444

#TimeUsernameProblemLanguageResultExecution timeMemory
885444epicci23Counting Mushrooms (IOI20_mushrooms)C++17
79.02 / 100
6 ms700 KiB
#include "mushrooms.h"
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define pb push_back
#define sz(x) ((int)(x).size())

const int BL = 120;

int count_mushrooms(int n){

  int ans=1,p=1;
  vector<int> ind_a,ind_b;
  ind_a.pb(0);

  for(int i=p;i<=min(n-1,BL);i++){
    p++;
    int xd = use_machine({0,i});
    if(xd==0){
      ans++;
      ind_a.pb(i);
    }
    else ind_b.pb(i);
    if(sz(ind_b)==2 || sz(ind_a)==2) break;
  }

  if(p>=n) return ans;

  for(int i=p;i<=min(n-1,2*BL);i+=2){
    if(i==n-1){
      p++;
      int xd = use_machine({0,i});
      if(xd==0){
       ans++;
       ind_a.pb(i);
      }
      else ind_b.pb(i);
      break;
    }
    p+=2;
    if(sz(ind_a)>=2){
      int xd = use_machine({i+1,ind_a[0],i,ind_a[1]});
      if(xd&2LL) ind_b.pb(i);
      else {ans++;ind_a.pb(i);}
      if(xd&1LL) ind_b.pb(i+1);
      else {ans++;ind_a.pb(i+1);}
    }
    else{
      int xd = use_machine({i+1,ind_b[0],i,ind_b[1]});
      if(xd&2LL) {ans++;ind_a.pb(i);}
      else ind_b.pb(i);
      if(xd&1LL) {ans++;ind_a.pb(i+1);}
      else ind_b.pb(i+1);
    }
  }

  if(p>=n) return ans;
  
  for(int i=p;i<n;i+=BL){
  	vector<int> que;
    for(int j=i;j<min(n,i+BL);j++) que.pb(j);

    if(sz(ind_a)>=BL){
      vector<int> haha;
      for(int j=0;j<sz(que);j++){
        haha.pb(que[j]);
        haha.pb(ind_a[j]);
      }
      int res = use_machine(haha);
      ans += sz(que) - 1 - res/2;
      ans += 1 - (res&1);
    }
    else{
      vector<int> haha;
      for(int j=0;j<sz(que);j++){
        haha.pb(que[j]);
        haha.pb(ind_b[j]);
      }
      int res = use_machine(haha);
      ans += res/2;
      ans += (res&1);
    } 
  }

  return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...