Submission #828314

#TimeUsernameProblemLanguageResultExecution timeMemory
828314tomrukCounting Mushrooms (IOI20_mushrooms)C++17
0 / 100
0 ms208 KiB
#include "mushrooms.h" #include <bits/stdc++.h> using namespace std; int count_mushrooms(int n) { vector<int> a = {0},b; int last = 1; int th = 0; int val = 1e9; for(int i = 1;i<n;i++){ if(3 + (i)/2 + n/i < val){ th = i; val = 3 + (i)/2 + n/i; } } while(last < n && max(a.size(),b.size()) < th){ if(last + 1 == n || max(a.size(),b.size()) == 1){ int num = use_machine({0,last}); if(num == 0) a.push_back(last); else b.push_back(last); last++; } else{ if(a.size() > b.size()){ int num = use_machine({last,a[0],last+1,a[1]}); if(num & 1){ b.push_back(last); } else a.push_back(last); if(num & 2){ b.push_back(last); } else a.push_back(last); last+=2; } else{ int num = use_machine({last,b[0],last+1,b[1]}); if(num & 1){ a.push_back(last); } else b.push_back(last); if(num & 2){ a.push_back(last); } else b.push_back(last); last+=2; } } } int ca = 0,cb = 0; while(last < n){ if(a.size() > b.size()){ int cnt = 0; vector<int> ask; while(cnt < a.size() && last < n){ ask.push_back(last); ask.push_back(a[cnt]); cnt++; last++; } int num = use_machine(ask); ca += cnt; ca -= num/2; ca -= num&1; } else{ int cnt = 0; vector<int> ask; while(cnt < b.size() && last < n){ ask.push_back(last); ask.push_back(b[cnt]); cnt++; last++; } int num = use_machine(ask); ca += num/2; ca += num&1; } } return a.size() + ca; }

Compilation message (stderr)

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:16:43: warning: comparison of integer expressions of different signedness: 'const long unsigned int' and 'int' [-Wsign-compare]
   16 |  while(last < n && max(a.size(),b.size()) < th){
      |                    ~~~~~~~~~~~~~~~~~~~~~~~^~~~
mushrooms.cpp:56:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |    while(cnt < a.size() && last < n){
      |          ~~~~^~~~~~~~~~
mushrooms.cpp:70:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |    while(cnt < b.size() && last < n){
      |          ~~~~^~~~~~~~~~
mushrooms.cpp:51:13: warning: unused variable 'cb' [-Wunused-variable]
   51 |  int ca = 0,cb = 0;
      |             ^~
#Verdict Execution timeMemoryGrader output
Fetching results...