Submission #1052608

#TimeUsernameProblemLanguageResultExecution timeMemory
1052608TahirAliyevCounting Mushrooms (IOI20_mushrooms)C++17
92.62 / 100
6 ms760 KiB
#include "mushrooms.h" #include <bits/stdc++.h> using namespace std; #define pii pair<int, int> #define ll long long #define all(v) v.begin(), v.end() #define oo 1e9 int count_mushrooms(int n){ srand(time(0)); // int B = 78; // pair<int, int> best = {oo, 0}; // for(int x = 3; x <= n; x++) best = min(best, {2 + (2 * (x - 2)) / 2 + (x & 1) + (n - 1) / x, x}); // B = best.second; // vector<int> id; for(int i = 0; i < n; i++) id.push_back(i); random_shuffle(id.begin() + 1, id.end()); vector<int> v[2]; v[0] = {0}; int i = 1; for(; i < min(3, n); i++){ v[use_machine({0, id[i]})].push_back(i); } int t = (v[0].size() < v[1].size()); for(; i + 1 < n && (int)max(v[0].size(), v[1].size()) < B; i += 2){ int a = use_machine({id[i], id[v[t][0]], id[i + 1], id[v[t][1]]}); v[t ^ (a & 1)].push_back(i); v[t ^ bool(a & 2)].push_back(i + 1); } if(i == n - 1){ v[use_machine({0, id[i]})].push_back(i); i++; } int ans = v[0].size(); if(i == n) return ans; while(i < n){ t = (v[0].size() < v[1].size()); vector<int> tmp; for(int j = 0; j < v[t].size() && i < n; j++, i++){ tmp.push_back(id[v[t][j]]); tmp.push_back(id[i]); } int a = use_machine(tmp); if(a & 1) v[t ^ 1].push_back(i - 1); else v[t].push_back(i - 1); if(t) ans += (a + 1) / 2; else ans += (tmp.size() / 2) - (a + 1) / 2; } return ans; }

Compilation message (stderr)

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:41:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |   for(int j = 0; j < v[t].size() && i < n; j++, i++){
      |                  ~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...