제출 #835420

#제출 시각아이디문제언어결과실행 시간메모리
835420BT21tata버섯 세기 (IOI20_mushrooms)C++17
0 / 100
0 ms208 KiB
#include "mushrooms.h"
#include<bits/stdc++.h>
#define pb push_back
using namespace std;

vector<int>a, b;

int count_mushrooms(int n)
{
	a.pb(0);
	int BLOCK=min((n-2)/2*2+1, 201);
	for(int i=1; i<min(n, BLOCK); i+=2)
	{
		int cnt=use_machine({i, 0, i+1});
		if(!cnt) a.pb(i), a.pb(i+1);
		else if(cnt==1)
		{
			if(use_machine({0, i})) b.pb(i), a.pb(i+1);
			else a.pb(i), b.pb(i+1);
		}
		else b.pb(i), b.pb(i+1);
	}
	if(a.size()>b.size())
	{
		int ansb=b.size();
		for(int i=BLOCK; i<n; i+=(a.size()-1))
		{
			vector<int>cur;
			int pos=0;
			for(int j=i; j<min(n, (int)(i+a.size()-1)); j++)
			{
				cur.pb(a[pos++]);
				cur.pb(j);
			}
			cur.pb(a[pos]);
			int ret=use_machine(cur);
			ansb+=(ret/2);
		}
		return n-ansb;
	}
	else
	{
		int ansa=a.size();
		for(int i=BLOCK; i<n; i+=(b.size()-1))
		{
			vector<int>cur;
			int pos=0;
			for(int j=i; j<min(n, (int)(i+b.size()-1)); j++)
			{
				cur.pb(b[pos++]);
				cur.pb(j);
			}
			cur.pb(b[pos]);
			int ret=use_machine(cur);
			ansa+=(ret/2);
		}
		return ansa;
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...