제출 #824541

#제출 시각아이디문제언어결과실행 시간메모리
824541ymm버섯 세기 (IOI20_mushrooms)C++17
80.71 / 100
8 ms508 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; int CNT = 0; int use_my_machine(vector<int> vec) { int res = use_machine(vec); ++CNT; return res; } #define use_machine use_my_machine 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); } } void queryx(vector<int> &A, vector<int> &B) { int u[5]; Loop (i,0,3) { u[i] = U.back(); U.pop_back(); } int res = use_machine({u[0], A[0], u[1], A[1], u[2], A[2]}); int r0 = res&1; res -= r0; (r0? B: A).push_back(u[0]); if (res == 0) { A.push_back(u[1]); A.push_back(u[2]); return; } if (res == 4) { B.push_back(u[1]); B.push_back(u[2]); return; } Loop (i,3,5) { u[i] = U.back(); U.pop_back(); } res = use_machine({u[3], A[0], u[4], A[1], u[1], A[2], B[0], u[2], B[1]}); res -= 1; int r3 = res/1%2; int r4 = res/2%2; int r12 = res/4%2; (r3? B: A).push_back(u[3]); (r4? B: A).push_back(u[4]); (r12? B: A).push_back(u[1]); (r12? A: B).push_back(u[2]); } int try_now() { int cnt = A.size() + B.size(); int rem = U.size(); int ans = 0; while (rem > 0) { int x = max<int>(max(A.size(), B.size()), (cnt+1)/2); x = min(x, rem); rem -= x; ++cnt; ++ans; return ans; } return ans; } int other_A = 0; void queryline() { if (!U.size()) return; auto &C = A.size() > B.size()? A: B; int cnt = min(C.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); while (CNT + try_now() > 240) { if (A.size() >= 3 && B.size() >= 2 && U.size() >= 5) queryx(A, B); else if (A.size() >= 2 && B.size() >= 3 && U.size() >= 5) queryx(B, A); else query2(); } while (U.size()) queryline(); return A.size() + other_A; }
#Verdict Execution timeMemoryGrader output
Fetching results...