Submission #1055599

#TimeUsernameProblemLanguageResultExecution timeMemory
1055599TrentCounting Mushrooms (IOI20_mushrooms)C++17
54.85 / 100
12 ms1368 KiB
#include "mushrooms.h" #include "bits/stdc++.h" using namespace std; #define forR(i, x) for(int i = 0; i < (x); ++i) #define REP(i, a, b) for(int i = (a); i < (b); ++i) #define all(x) x.begin(), x.end() typedef vector<int> vi; typedef vector<bool> vb; typedef long long ll; typedef vector<ll> vll; typedef set<int> si; int count_mushrooms(int n) { int IVL = n <= 200 ? 1 : 130; vi chk; for(int i = 0; i < n; i += IVL) chk.push_back(i); if(chk.back() < n-1) chk.push_back(n-1); vi ty(chk.size()); ty[0] = 0; REP(i, 1, chk.size()) { vi tst = {0, chk[i]}; ty[i] = use_machine(tst) == 0 ? 0 : 1; } vi ac, bc; forR(i, chk.size()) { if(ty[i] == 0) ac.push_back(chk[i]); else bc.push_back(chk[i]); } vb usd(n, false); for(int i : chk) usd[i] = true; si emp; forR(i, n) if(!usd[i]) emp.insert(i); int tot = ac.size(); while(!emp.empty()) { int amt = min(max(ac.size(), bc.size()), emp.size() + 1); if(ac.size() > bc.size()) { vi qu; forR(i, amt - 1) { qu.push_back(ac[i]); qu.push_back(*emp.begin()); emp.erase(qu.back()); } qu.push_back(ac[amt - 1]); int ret = use_machine(qu); cerr << qu.size() << ' ' << ret << '\n'; tot += amt - 1 - ret / 2; } else { vi qu; forR(i, amt - 1) { qu.push_back(bc[i]); qu.push_back(*emp.begin()); emp.erase(qu.back()); } qu.push_back(bc[amt - 1]); int ret = use_machine(qu); cerr << qu.size() << ' ' << ret << '\n'; tot += ret / 2; } } return tot; }

Compilation message (stderr)

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:5:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    5 | #define REP(i, a, b) for(int i = (a); i < (b); ++i)
      |                                         ^
mushrooms.cpp:20:2: note: in expansion of macro 'REP'
   20 |  REP(i, 1, chk.size()) {
      |  ^~~
mushrooms.cpp:4:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forR(i, x) for(int i = 0; i < (x); ++i)
      |                                     ^
mushrooms.cpp:26:2: note: in expansion of macro 'forR'
   26 |  forR(i, chk.size()) {
      |  ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...