Submission #604520

#TimeUsernameProblemLanguageResultExecution timeMemory
604520gagik_2007Counting Mushrooms (IOI20_mushrooms)C++17
92.62 / 100
15 ms340 KiB
#include "mushrooms.h" #include <iostream> #include <algorithm> #include <string> #include <vector> #include <cmath> #include <ctime> #include <set> #include <map> #include <stack> #include <queue> #include <deque> #include <limits> #include <iomanip> #include <unordered_set> #include <unordered_map> #include <random> using namespace std; typedef long long ll; typedef long double ld; typedef ll itn; #define ff first #define ss second ll n; vector<int>A, B; int count_mushrooms(int N) { n = N; const int VAL = 6 * int(sqrt(n)) / 5; pair<int, int>sm; vector<int>ask = { 0,1 }; int vl = use_machine(ask); int anh = -1; bool sma = true; ll ans = 0; A.push_back(0); if (vl == 0) { if (n == 2)return 2; sm = { 0,1 }; anh = 2; ans = 2; A.push_back(1); } else { if (n == 2)return 1; B.push_back(1); ask = { 1,2 }; vl = use_machine(ask); anh = 3; if (vl == 1) { if (n == 3)return 2; sm = { 0,2 }; A.push_back(2); ans = 2; } else { if (n == 3)return 1; sm = { 1,2 }; B.push_back(2); ans = 1; sma = false; } } for (int i = anh; i < VAL; i += 2) { if (i == VAL - 1) { ask = { 0,i }; vl = use_machine(ask); if (!vl) { ans++; A.push_back(i); } else { B.push_back(i); } break; } ask = { sm.ff,i,sm.ss,i + 1 }; vl = use_machine(ask); //cout << vl << " "; if (sma) { switch (vl) { case 0: A.push_back(i); A.push_back(i + 1); ans += 2; break; case 1: A.push_back(i); B.push_back(i + 1); ans += 1; break; case 2: B.push_back(i); A.push_back(i + 1); ans += 1; break; case 3: B.push_back(i); B.push_back(i + 1); break; } } else { switch (vl) { case 0: B.push_back(i); B.push_back(i + 1); break; case 1: B.push_back(i); A.push_back(i + 1); ans += 1; break; case 2: A.push_back(i); B.push_back(i + 1); ans += 1; break; case 3: A.push_back(i); A.push_back(i + 1); ans += 2; break; } } } int ind = max(anh, VAL); while (ind != n) { if (A.size() >= B.size()) { ask.clear(); int cnt = 0; while (cnt != A.size() && ind != n) { ask.push_back(A[cnt]); ask.push_back(ind); cnt++; ind++; } vl = use_machine(ask); /*for (int x : ask) { cout << x << " "; }*/ //cout << "-> " << vl << endl; ans += cnt; if (vl % 2 != 0) { ans--; vl--; B.push_back(ind - 1); } else { A.push_back(ind - 1); } ans -= vl / 2; //cout << ans << endl; } else { ask.clear(); int cnt = 0; while (cnt != B.size() && ind != n) { ask.push_back(B[cnt]); ask.push_back(ind); cnt++; ind++; } vl = use_machine(ask); if (vl % 2 != 0) { ans++; vl--; A.push_back(ind - 1); } else { B.push_back(ind - 1); } ans += vl / 2; } } return ans; } /* 7 0 0 1 0 0 1 1 8 0 0 0 0 0 0 0 0 20 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 20 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 */

Compilation message (stderr)

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:137:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  137 |    while (cnt != A.size() && ind != n) {
      |           ~~~~^~~~~~~~~~~
mushrooms.cpp:163:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  163 |    while (cnt != B.size() && ind != n) {
      |           ~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...