Submission #331859

#TimeUsernameProblemLanguageResultExecution timeMemory
331859pggpCounting Mushrooms (IOI20_mushrooms)C++14
25 / 100
134 ms492 KiB
#include <bits/stdc++.h>
#include "mushrooms.h"

using namespace std;


vector < bool > mushrooms;

int use_machine(vector < int > x);

int count_mushrooms(int n){
	int ans = 1;
	if(n < 5){
		for (int i = 1; i < n; ++i)
		{
			vector < int > v;
			v.push_back(0);
			v.push_back(i);
			ans += 1 - use_machine(v);
		}
		return ans;
	}

	int A_pos;
	int start_ind = 2;
	// 1st part
	for (int i = 1; i < n - 1; i += 2)
	{
		start_ind = i + 2;
		vector < int > v;
		v.push_back(0);
		v.push_back(i);
		v.push_back(i + 1);
		int resp = use_machine(v);
		if(resp == 0){
			ans += 2;
			A_pos = i;
			break;
		}
		if(resp == 1){
			v.clear();
			v.push_back(0);
			v.push_back(i);
			if(use_machine(v) == 1){
				// i to B
			}
			else{
				ans += 1;
				A_pos = i;
				break;
			}
			
		}
		if(resp == 2){
			ans += 1;
			A_pos = i + 1;
			break;
		}
	}

	//cout << "start_ind = " << start_ind << endl;
	//cout << "A_pos = " << A_pos << endl;
	//cout << "[przed policzeniem] ans = " << ans << endl;
	
	// 2nd part
	if((start_ind % 2) != (n % 2) and n % 2 == 0){
		vector < int > v;
		v.push_back(0);
		v.push_back(n - 1);
		ans += 1 - use_machine(v);
	}
	for (int i = start_ind; i < n - 1; i += 2)
	{
		vector < int > v;
		v.push_back(0);
		v.push_back(i);
		v.push_back(A_pos);
		v.push_back(i + 1);
		int resp = use_machine(v);
		switch(resp){
			case 0:
				ans += 2;
				//cout << "0";
				break;
			case 1:
				ans += 1;
				//cout << "1";
				break;
			case 2:
				ans += 1;
				//cout << "2";
				break;
			case 3:
				ans += 0;
				//cout << "3";
				break;
		}
	}

	
	return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...