Submission #305927

#TimeUsernameProblemLanguageResultExecution timeMemory
305927myungwooCounting Mushrooms (IOI20_mushrooms)C++17
92.24 / 100
11 ms384 KiB
#include <bits/stdc++.h> #include "mushrooms.h" using namespace std; int count_mushrooms(int N) { int iter = 71; vector<int> arr[2] = {{0}, {}}; int pt = 1; // Step 1: Check type of mushroom one by one while (pt < N){ arr[use_machine({0, pt})].push_back(pt); pt++; if (arr[0].size() >= 2 || arr[1].size() >= 2) break; } // Step 2: Check type of mushroom two by one while (pt < N){ int t = arr[1].size() >= 2; vector<int> test = {arr[t][0], pt, arr[t][1]}; if (pt+1 < N) test.push_back(pt+1); int res = use_machine(test); arr[res>>1&1^t].push_back(pt); if (pt+1 < N) arr[res&1^t].push_back(pt+1); pt += 2; if (!--iter) break; } // Step 3: Count number of type 0 mushrooms s by one int zero_count = arr[0].size(); while (pt < N){ int t = arr[1].size() > arr[0].size(); vector<int> test; for (int i=0;pt+i<N&&i<arr[t].size();i++){ test.push_back(arr[t][i]); test.push_back(pt+i); } int res = use_machine(test); arr[res&1^t].push_back(test.back()); int cnt = res+1>>1; if (!t) cnt = test.size()/2-cnt; zero_count += cnt; pt += test.size()/2; } return zero_count; }

Compilation message (stderr)

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:22:13: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   22 |   arr[res>>1&1^t].push_back(pt);
      |       ~~~~~~^~
mushrooms.cpp:23:24: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   23 |   if (pt+1 < N) arr[res&1^t].push_back(pt+1);
      |                     ~~~^~
mushrooms.cpp:32:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |   for (int i=0;pt+i<N&&i<arr[t].size();i++){
      |                        ~^~~~~~~~~~~~~~
mushrooms.cpp:37:10: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   37 |   arr[res&1^t].push_back(test.back());
      |       ~~~^~
mushrooms.cpp:38:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   38 |   int cnt = res+1>>1;
      |             ~~~^~
#Verdict Execution timeMemoryGrader output
Fetching results...