Submission #1052288

#TimeUsernameProblemLanguageResultExecution timeMemory
1052288TahirAliyevCounting Mushrooms (IOI20_mushrooms)C++17
64.39 / 100
6 ms600 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 B = 141; int count_mushrooms(int n){ pii best = {oo, 0}; for(int x = 3; x <= n; x++){ best = min(best, {x + n / x, x}); } B = best.first; 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; t = (v[0].size() < v[1].size()); while(i < n){ 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]); } if(t) ans += (use_machine(tmp) + 1) / 2; else ans += (tmp.size() / 2) - (use_machine(tmp) + 1) / 2; } return ans; }

Compilation message (stderr)

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