Submission #624764

#TimeUsernameProblemLanguageResultExecution timeMemory
624764Dremix10Counting Mushrooms (IOI20_mushrooms)C++17
84.01 / 100
9 ms324 KiB
#include "mushrooms.h"
#include <bits/stdc++.h>
using namespace std;


int count_mushrooms(int n) {
	vector<int> arr[2];
	bool B = 1;

	int i,k,x;
	const int init = 220;
	
	vector<int> temp;
	temp.push_back(0);
	arr[0].push_back(0);

	int res = 0;

	for(i=1;i<=min(n-1,2);i++){
		temp.push_back(i);
		x = use_machine(temp);
		temp.pop_back();

		arr[x].push_back(i);
	}

	temp.pop_back();

	if(arr[0].size() > arr[1].size())
		B = 0;
	
	//assert(arr[B].size() >= 2);
	temp.push_back(arr[B][0]);
	temp.push_back(-1);
	if(arr[B].size() > 1){
		temp.push_back(arr[B][1]);
	}
	temp.push_back(-1);

	for(k=3;k<=min(n-2,init-1);k+=2){
		temp[1] = k;
		temp[3] = k+1;
		x = use_machine(temp);

		if(x >= 2){
			/// middle one is different
			arr[B^1].push_back(k);
		}
		else{
			arr[B].push_back(k);
		}

		if(x % 2){
			/// right one is diff
			arr[B^1].push_back(k+1);
		}
		else{
			arr[B].push_back(k+1);
		}
	}
	if(n%2 == 0 && k == n-1 && n != 2){
		temp = {0,n-1};
		x = use_machine(temp);
		if(!x)res++;
	}

	k = init + 1;
	res += arr[0].size();
	while(k<n){
		temp.clear();
		B = 1;
		if(arr[0].size() > arr[1].size())
			B = 0;
		for(i=0;i<arr[B].size() && k < n;i++){
			temp.push_back(arr[B][i]);
			temp.push_back(k);
			k++;
		}

		x = use_machine(temp);
		int diff = x/2;

		if(x%2){
			diff++;
			arr[B^1].push_back(temp.back());
		}

		if(B)
			res += diff;
		else
			res += temp.size()/2 - diff;

	}

	return res;
}

Compilation message (stderr)

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:74:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |   for(i=0;i<arr[B].size() && k < n;i++){
      |           ~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...