Submission #817502

#TimeUsernameProblemLanguageResultExecution timeMemory
817502math_rabbit_1028Counting Mushrooms (IOI20_mushrooms)C++14
0 / 100
2 ms464 KiB
#include "mushrooms.h" #include <bits/stdc++.h> using namespace std; int count_mushrooms(int n) { int b = max((int)sqrt(n), 2); vector<int> Alist, Blist; Alist.push_back(0); int i, ans = Alist.size(); if (n <= 200) { for (int i = 1; i < n; i++) if (use_machine({Alist[0], i}) == 0) ans++; return ans; } assert(n <= 19999); if (use_machine({0, 1}) == 0) { Alist.push_back(1); for (i = 2; i < n; i += 2) { int ret = use_machine({Alist[0], i, Alist[1], i + 1}); if (ret >= 2) Blist.push_back(i); else Alist.push_back(i); if (ret % 2 == 0) Alist.push_back(i + 1); else Blist.push_back(i + 1); if (Alist.size() == b || Blist.size() == b) break; } } else { Blist.push_back(1); if (use_machine({0, 2}) == 0) { Alist.push_back(2); for (i = 3; i < n; i += 2) { int ret = use_machine({Alist[0], i, Alist[1], i + 1}); if (ret >= 2) Blist.push_back(i); else Alist.push_back(i); if (ret % 2 == 0) Alist.push_back(i + 1); else Blist.push_back(i + 1); if (Alist.size() == b || Blist.size() == b) break; } } else { Blist.push_back(2); for (i = 3; i < n; i += 2) { int ret = use_machine({Blist[0], i, Blist[1], i + 1}); if (ret >= 2) Alist.push_back(i); else Blist.push_back(i); if (ret % 2 == 0) Blist.push_back(i + 1); else Alist.push_back(i + 1); if (Alist.size() == b || Blist.size() == b) break; } } } ans = Alist.size(); i += 2; for (; i < n; i += b) { vector<int> seq; if (Alist.size() == b) { for (int j = i; j < min(i + b, n); j++) { seq.push_back(Alist[j - i]); seq.push_back(j); } ans += (min(i + b, n) - i) - (use_machine(seq) + 1) / 2; } else { for (int j = i; j < min(i + b, n); j++) { seq.push_back(Blist[j - i]); seq.push_back(j); } ans += (use_machine(seq) + 1) / 2; } } return ans; }

Compilation message (stderr)

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:26:30: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   26 |             if (Alist.size() == b || Blist.size() == b) break;
      |                 ~~~~~~~~~~~~~^~~~
mushrooms.cpp:26:51: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   26 |             if (Alist.size() == b || Blist.size() == b) break;
      |                                      ~~~~~~~~~~~~~^~~~
mushrooms.cpp:39:34: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   39 |                 if (Alist.size() == b || Blist.size() == b) break;
      |                     ~~~~~~~~~~~~~^~~~
mushrooms.cpp:39:55: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   39 |                 if (Alist.size() == b || Blist.size() == b) break;
      |                                          ~~~~~~~~~~~~~^~~~
mushrooms.cpp:50:34: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   50 |                 if (Alist.size() == b || Blist.size() == b) break;
      |                     ~~~~~~~~~~~~~^~~~
mushrooms.cpp:50:55: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   50 |                 if (Alist.size() == b || Blist.size() == b) break;
      |                                          ~~~~~~~~~~~~~^~~~
mushrooms.cpp:59:26: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   59 |         if (Alist.size() == b) {
      |             ~~~~~~~~~~~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...