Submission #604672

#TimeUsernameProblemLanguageResultExecution timeMemory
604672CyberCowCounting Mushrooms (IOI20_mushrooms)C++17
0 / 100
13 ms332 KiB
#include "mushrooms.h"
#include <vector>
using namespace std;
int a[20006];

int count_mushrooms(int n) {
	int l = 0, r = n - 1;
	vector<int>v;
	int i, j;
	for ( i = 0; i < n; i++)
	{
		v.push_back(i);
	}
	int qan = use_machine(v);
	int zr = 0, mazr = 0;
	a[qan] = n - 1;
	for (i = 0; i < qan; i++)
	{
		zr = 0;
		mazr = 0;
		if(i)
			l = a[i - 1] + 1;
		for ( j = i + 1; j <= qan; j++)
		{
			if (a[j])
			{
				r = a[j] - 1;
				break;
			}
		}
		if (i && a[i - 1] + 2 == a[i + 1])
		{
			a[i] = a[i - 1] + 1;
			continue;
		}
		while (l <= r)
		{
			int m = (l + r) >> 1;
			if (!m)
				break;
			v.clear();
			for (j = 0; j <= m; j++)
			{
				v.push_back(j);
			}
			int x = use_machine(v);
			a[x] = max(m, a[x]);
			if (x > i)
			{
				r = m - 1;
			}
			else
			{
				l = m + 1;
			}
		}
	}
	int ans = a[0];
	if (qan % 2)
		qan--;
	for ( i = 1; i < qan; i+=2)
	{
		ans += a[i + 1] - a[i];
	}
	return ans + 1;
}

Compilation message (stderr)

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:15:6: warning: variable 'zr' set but not used [-Wunused-but-set-variable]
   15 |  int zr = 0, mazr = 0;
      |      ^~
mushrooms.cpp:15:14: warning: variable 'mazr' set but not used [-Wunused-but-set-variable]
   15 |  int zr = 0, mazr = 0;
      |              ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...