제출 #399173

#제출 시각아이디문제언어결과실행 시간메모리
399173Antekb버섯 세기 (IOI20_mushrooms)C++14
92.62 / 100
9 ms456 KiB
#include "mushrooms.h"
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb(x) push_back(x)
using namespace std;
int count_mushrooms(int n) {
	vector<int> A, B, C(n-1);
	A.pb(0);
	iota(C.begin(), C.end(), 1);
	int k=81;
	for(int i=0; i<2 && C.size(); i++){
		int c1 = use_machine({0, C.back()});
		if(c1==1)B.pb(C.back());
		else A.pb(C.back());
		C.pop_back();
	}
	bool swa=0;
	if(A.size()<B.size()){
		swap(A, B);
		swa=1;
	}
	for(int i=0; i<k && C.size()>1; i++){
		int c1 = use_machine({A[0], C.back(), A[1], C[C.size()-2]});
		if(c1>=2)B.pb(C.back());
		else A.pb(C.back());
		C.pop_back();
		if(c1&1)B.pb(C.back());
		else A.pb(C.back());
		C.pop_back();
	}
	int a=A.size(), b=B.size();
	while(C.size()){
		/*cout<<"A: ";
		for(int i:A)cout<<i<<" ";
			cout<<"\n";
		cout<<"B: ";
		for(int i:B)cout<<i<<" ";
			cout<<"\n";
		cout<<a<<" "<<b<<"\n";*/
		if(A.size()<B.size()){
			//cout<<"...";
			swap(A, B);
			swap(a, b);
			swa^=1;
		}
		int t=min(A.size(), C.size());
		vector<int> V;
		for(int i=0; i<t; i++){
			V.pb(A[i]);
			V.pb(C.back());
			C.pop_back();
		}
		int c=use_machine(V);
		//cout<<t<<" "<<c<<"\n";
		b+=(c+1)/2;
		a+=t-(c+1)/2;
		if(c&1)B.pb(V.back());
		else A.pb(V.back());
	}
	if(swa)swap(a, b);
	return a;
}
#Verdict Execution timeMemoryGrader output
Fetching results...