Submission #1022955

#TimeUsernameProblemLanguageResultExecution timeMemory
1022955TheWilpCounting Mushrooms (IOI20_mushrooms)C++14
80.71 / 100
7 ms708 KiB
#include "mushrooms.h"

int count_mushrooms(int n) {
	if(n == 1) return 1;
	std::vector<int> A;
	std::vector<int> B;
	A.push_back(0);
	int ans = 0;

	int i = 1;
	while(i < n) {
		bool Abase = B.size() <= A.size();
		std::vector<int>* in = Abase ? &A : &B;
		std::vector<int> v;

		int c = 1;
		v.push_back((*in)[0]);
		while(i < n) {
			if(c < in->size()) {
				v.push_back(i++);
				v.push_back((*in)[c++]);
			}
			else {
				break;
			}
		}
		bool pos_push = false;
		if(i < n) v.push_back(i++),pos_push = true;
		int count = use_machine(v);
		if(Abase) {
			ans += (v.size() + 1) / 2 - 1 - count / 2;
			if(pos_push) 
				if(count%2) B.push_back(v.back());
				else A.push_back(v.back());
		}
		else {
			ans += count / 2;
			if(pos_push) 
				if(count%2) A.push_back(v.back());
				else B.push_back(v.back());
		}
	}
	return ans + A.size();
}

Compilation message (stderr)

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:19:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |    if(c < in->size()) {
      |       ~~^~~~~~~~~~~~
mushrooms.cpp:32:6: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
   32 |    if(pos_push)
      |      ^
mushrooms.cpp:38:6: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
   38 |    if(pos_push)
      |      ^
#Verdict Execution timeMemoryGrader output
Fetching results...