Submission #1090595

#TimeUsernameProblemLanguageResultExecution timeMemory
1090595onlk97Counting Mushrooms (IOI20_mushrooms)C++14
56.93 / 100
6 ms600 KiB
#include "mushrooms.h" #include <bits/stdc++.h> using namespace std; const int Q=186; int count_mushrooms(int n){ if (n<=Q+1){ vector <int> v(n); v[0]=0; for (int i=1; i<n; i++){ int tp=use_machine({i-1,i}); if (tp) v[i]=v[i-1]^1; else v[i]=v[i-1]; } return count(v.begin(),v.end(),0); } vector <int> v(Q+1); v[0]=0; for (int i=1; i<=Q; i++){ int tp=use_machine({i-1,i}); if (tp) v[i]=v[i-1]^1; else v[i]=v[i-1]; } int cnt0=count(v.begin(),v.end(),0),cnt1=count(v.begin(),v.end(),1); int ans=cnt0; if (cnt0>=cnt1){ vector <int> pos; for (int i=0; i<=Q; i++) if (!v[i]) pos.push_back(i); for (int i=Q+1; i<n; i+=pos.size()){ vector <int> ths; for (int j=i; j<min(n,i+(int)pos.size()); j++) ths.push_back(j); vector <int> ask; for (int j=0; j<ths.size(); j++){ ask.push_back(pos[j]); ask.push_back(ths[j]); } int ret=ask.size()-1-use_machine(ask); ans+=(ret+1)/2; } } else { vector <int> pos; for (int i=0; i<=Q; i++) if (v[i]) pos.push_back(i); for (int i=Q+1; i<n; i+=pos.size()){ vector <int> ths; for (int j=i; j<min(n,i+(int)pos.size()); j++) ths.push_back(j); vector <int> ask; for (int j=0; j<ths.size(); j++){ ask.push_back(pos[j]); ask.push_back(ths[j]); } int ret=ask.size()-1-use_machine(ask); ans+=(int)ths.size()-(ret+1)/2; } } return ans; }

Compilation message (stderr)

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:32:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |             for (int j=0; j<ths.size(); j++){
      |                           ~^~~~~~~~~~~
mushrooms.cpp:46:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |             for (int j=0; j<ths.size(); j++){
      |                           ~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...