Submission #824436

#TimeUsernameProblemLanguageResultExecution timeMemory
824436ymmCounting Mushrooms (IOI20_mushrooms)C++17
35.15 / 100
7 ms512 KiB
#include "mushrooms.h" #include <bits/stdc++.h> #define Loop(x,l,r) for (ll x = (l); x < (r); ++x) typedef long long ll; typedef std::pair<ll,ll> pll; using namespace std; vector<int> A, B, U; void query1() { if (!U.size()) return; int x = U.back(); U.pop_back(); (use_machine({0, x})? B: A).push_back(x); } void query2() { if (U.size() < 2 || (A.size() < 2 && B.size() < 2)) return query1(); int x = U.back(); U.pop_back(); int y = U.back(); U.pop_back(); if (A.size() >= 2) { int res = use_machine({A[0], x, A[1], y}); int a = res/2; int b = res%2; (a? B: A).push_back(x); (b? B: A).push_back(y); } else { int res = use_machine({B[0], x, B[1], y}); int a = res/2; int b = res%2; (a? A: B).push_back(x); (b? A: B).push_back(y); } } int other_A = 0; void queryline() { if (!U.size()) return; auto &C = A.size() > B.size()? A: B; int cnt = min(A.size(), U.size()); vector<int> vec; int lst = -1; Loop (i,0,cnt) { vec.push_back(C[i]); vec.push_back(U.back()); lst = U.back(); U.pop_back(); } int res = use_machine(vec); int rl = res&1; if (A.size() > B.size()) { other_A += cnt-1-res/2; (rl? B: A).push_back(lst); } else { other_A += res/2; (rl? A: B).push_back(lst); } } int count_mushrooms(int n) { A.clear(); U.clear(); B.clear(); other_A = 0; A.push_back(0); Loop (i,1,n) U.push_back(i); Loop (_,0,100) query2(); while (U.size()) queryline(); return A.size() + other_A; }
#Verdict Execution timeMemoryGrader output
Fetching results...