Submission #601958

#TimeUsernameProblemLanguageResultExecution timeMemory
601958FatihSolakCounting Mushrooms (IOI20_mushrooms)C++17
0 / 100
2 ms208 KiB
#include "mushrooms.h" #include <bits/stdc++.h> #define N 20000 #define X 187 using namespace std; int count_mushrooms(int n){ int mini = 0; int val = 1e9; for(int i = 1;i<N;i++){ if(i-1 + (N - i + (i+1)/2 -1)/( (i+1)/2) < val){ val = i-1 + (N - i + (i+1)/2 -1)/( (i+1)/2); mini = i; } } //cout << mini << " " << val << endl; if(n <= 227){ int ret = 1; for(int i = 1;i<n;i++){ ret += !(use_machine({0,i})); } return ret; } vector<int> a,b; a.push_back(0); int point = 1; int cur = 0; while( (n-point + max(a.size(),b.size()) - 1) / max(a.size(),b.size()) + cur > 300 ){ int asz = a.size(); int bsz = b.size(); if(asz > bsz){ int len = 0; while((1<<(len+1)) <= asz * 2){ len++; } vector<int> points; vector<int> ask; int cnt = 0; for(int i = len-1;i>=0;i--){ for(int j = 0;j<(1<<i);j++){ ask.push_back(a[cnt++]); ask.push_back(point); } points.push_back(point); point++; } reverse(points.begin(),points.end()); int mask = use_machine(ask); for(int i = 0;i<len;i++){ if(mask & (1<<i)){ b.push_back(points[i]); } else a.push_back(points[i]); } } else{ int len = 0; while((1<<(len+1)) <= bsz * 2){ len++; } vector<int> points; vector<int> ask; int cnt = 0; for(int i = len-1;i>=0;i--){ for(int j = 0;j<(1<<i);j++){ ask.push_back(b[cnt++]); ask.push_back(point); } points.push_back(point); point++; } reverse(points.begin(),points.end()); int mask = use_machine(ask); for(int i = 0;i<len;i++){ if(mask & (1<<i)){ a.push_back(points[i]); } else b.push_back(points[i]); } } cur++; } // for(int i = 1;i<=X;i++){ // if(use_machine({0,i})){ // b.push_back(i); // } // else a.push_back(i); // } int ret = 0; int asz = a.size(); int bsz = b.size(); if(asz > bsz){ for(int i = X+1;i<n;i+=asz){ vector<int> nums; int cnt = 0; for(int j = i;j<min(n,i + asz);j++){ nums.push_back(a[cnt++]); nums.push_back(j); } int sz = nums.size()/2; ret += sz - (use_machine(nums) + 1)/2; } } else{ for(int i = X+1;i<n;i+=bsz){ vector<int> nums; int cnt = 0; for(int j = i;j<min(n,i + bsz);j++){ nums.push_back(b[cnt++]); nums.push_back(j); } int sz = nums.size()/2; ret += (use_machine(nums) + 1)/2; } } return ret + asz; }

Compilation message (stderr)

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:112:8: warning: unused variable 'sz' [-Wunused-variable]
  112 |    int sz = nums.size()/2;
      |        ^~
mushrooms.cpp:8:6: warning: variable 'mini' set but not used [-Wunused-but-set-variable]
    8 |  int mini = 0;
      |      ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...