Submission #828665

#TimeUsernameProblemLanguageResultExecution timeMemory
828665Abrar_Al_SamitCounting Mushrooms (IOI20_mushrooms)C++17
0 / 100
6 ms380 KiB
#include <bits/stdc++.h> #include "mushrooms.h" using namespace std; const int bl = 300; int count_mushrooms(int n) { vector<int>mac; int c1 = use_machine(mac = {0, 1}); if(n==2) return 1 + 1-c1; int c2 = use_machine(mac = {0, 2}); int tp[n]; tp[0] = 1; tp[1] = 1-c1; tp[2] = 1-c2; int s1, s2; if(c1 && c2) s1 = 1, s2 = 2; else { s1 = 0; if(c1) s2 = 2; else s2 = 1; } if(n==3) { return tp[0] + tp[1] + tp[2]; } int cnt[2] = {0}; int upto; for(int i=3; i<min(bl, n); i+=2) { if(i==n-1) { tp[i] = 1 - use_machine(mac = {0, i}); upto = i; } else { int c = use_machine(mac = {i, s1, i+1, s2}); if(c==0) { tp[i] = tp[i+1] = tp[s1]; } else if(c==1) { tp[i] = 1-tp[s1]; tp[i+1] = tp[s1]; } else if(c==2) { tp[i+1] = 1-tp[s1]; tp[i] = tp[s1]; } else { tp[i] = tp[i+1] = 1-tp[s1]; } ++cnt[tp[i]], ++cnt[tp[i+1]]; upto = i+1; if(max(cnt[tp[i]], cnt[tp[i+1]])>=bl/2) { break; } } } int ans = 0; vector<int>cl[2]; for(int i=0; i<=upto; ++i) { cl[tp[i]].push_back(i); ans += tp[i]; } if(upto == n-1) return ans; int cr = upto + 1; while(cr < n) { mac.clear(); bool mxw = 0; if(cl[1].size()>=cl[0].size()) mxw = 1; mac = {cr}; int f = cr; ++cr; for(int j=0; j<cl[mxw].size(); ++j) { mac.push_back(cl[mxw][j]); if(cr==n) { while(cl[mxw].size()!=j+1) cl[mxw].pop_back(); break; } if(j!=cl[mxw].size()-1) mac.push_back(cr), ++cr; } int get = use_machine(mac); if(get & 1) { cl[1-mxw].push_back(f); --get; } else { cl[mxw].push_back(f); } ans += 1-mxw; if(!mxw) ans += get / 2; else ans += ((cl[mxw].size()-1) * 2 - get) / 2; } return ans; }

Compilation message (stderr)

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:82:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |   for(int j=0; j<cl[mxw].size(); ++j) {
      |                ~^~~~~~~~~~~~~~~
mushrooms.cpp:85:25: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   85 |     while(cl[mxw].size()!=j+1) cl[mxw].pop_back();
      |           ~~~~~~~~~~~~~~^~~~~
mushrooms.cpp:89:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |    if(j!=cl[mxw].size()-1) mac.push_back(cr), ++cr;
      |       ~^~~~~~~~~~~~~~~~~~
mushrooms.cpp:70:2: warning: 'upto' may be used uninitialized in this function [-Wmaybe-uninitialized]
   70 |  if(upto == n-1) return ans;
      |  ^~
#Verdict Execution timeMemoryGrader output
Fetching results...