Submission #697401

#TimeUsernameProblemLanguageResultExecution timeMemory
697401garam1732Counting Mushrooms (IOI20_mushrooms)C++14
87.94 / 100
15 ms428 KiB
#include "mushrooms.h" #include <bits/stdc++.h> using namespace std; vector<int> a, b; int cnt = 140; int count_mushrooms(int n) { a.push_back(0); std::vector<int> m; use_machine({0, 1}) ? b.push_back(1) : a.push_back(1); if(n == 2) return a.size(); use_machine({0, 2}) ? b.push_back(2) : a.push_back(2); if(a.size() > 1) { for(int i = 4; i <= n && i <= 2*cnt; i += 2) { m = {a[0], i-1, a[1], i}; if(i == n) { m.pop_back(); int res = use_machine(m); res ? b.push_back(i-1) : a.push_back(i-1); } else { int res = use_machine(m); (res < 2) ? a.push_back(i-1) : b.push_back(i-1); (res & 1) ? b.push_back(i) : a.push_back(i); } } } else { for(int i = 4; i <= n && i <= 2*cnt; i += 2) { m = {b[0], i-1, b[1], i}; if(i == n) { m.pop_back(); int res = use_machine(m); res ? a.push_back(i-1) : b.push_back(i-1); } else { int res = use_machine(m); (res < 2) ? b.push_back(i-1) : a.push_back(i-1); (res & 1) ? a.push_back(i) : b.push_back(i); } } } if(a.size() + b.size() == n) return a.size(); int res = a.size(), idx = 2*cnt+1; while(idx < n) { if(a.size() > b.size()) { int z; m.clear(); for(int i = 0; i < a.size(); i++) { if(idx < n) { if(i == 0) z = idx; m.push_back(idx++); } m.push_back(a[i]); } int x = use_machine(m); res += (int)m.size() - (int)a.size() - (x+1)/2; (x%2) ? b.push_back(z) : a.push_back(z); } else { int z; m.clear(); for(int i = 0; i < b.size(); i++) { if(idx < n) { if(i == 0) z = idx; m.push_back(idx++); } m.push_back(b[i]); } int x = use_machine(m); res += (x+1)/2; (x%2) ? a.push_back(z) : b.push_back(z); } } return res; }

Compilation message (stderr)

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:48:25: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   48 |  if(a.size() + b.size() == n) return a.size();
      |     ~~~~~~~~~~~~~~~~~~~~^~~~
mushrooms.cpp:55:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |             for(int i = 0; i < a.size(); i++) {
      |                            ~~^~~~~~~~~~
mushrooms.cpp:70:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |             for(int i = 0; i < b.size(); i++) {
      |                            ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...