Submission #1052399

# Submission time Handle Problem Language Result Execution time Memory
1052399 2024-08-10T14:17:15 Z aykhn Counting Mushrooms (IOI20_mushrooms) C++17
0 / 100
5 ms 344 KB
#include "mushrooms.h"
#include <bits/stdc++.h>

using namespace std;

int B = 137;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int count_mushrooms(int n) 
{
	vector<int> v[2];
	vector<int> o(n);
	iota(o.begin(), o.end(), 0);
	shuffle(o.begin() + 1, o.end(), rng);
	v[0] = {0};
	int i = 1;
	while (i < n && max(v[0].size(), v[1].size()) < 2) v[use_machine({0, o[i]})].push_back(o[i]), i++;
	for (; i < n && max(v[0].size(), v[1].size()) < B; i += 2) 
	{
		if (i + 1 < n)
		{
			if (v[0].size() >= 2)
			{
				int x = use_machine({v[0][0], o[i], v[0][1], o[i + 1]});
				v[x >> 1 & 1].push_back(o[i]);
				v[x & 1].push_back(o[i + 1]);
			}
			else
			{
				int x = use_machine({v[1][0], o[i], v[1][1], o[i + 1]});
				v[1 ^ (x >> 1 & 1)].push_back(o[i]);
				v[1 ^ (x & 1)].push_back(o[i + 1]);
			}
		}
		else v[use_machine({0, o[i]})].push_back(o[i]);
	}
	int res = 0;
	for (int j = i; j < n; j += B)
	{
		vector<int> q;
		int sz = min(n, j + B) - j;
		for (int k = j; k < min(n, j + B); k++)
		{
			if (v[0].size() > v[1].size())
			{
				q.push_back(v[0][k - j]);
				q.push_back(o[k]);
			}
			else
			{
				q.push_back(v[1][k - j]);
				q.push_back(o[k]);
			}
		}
		if (v[0].size() > v[1].size())
		{
			int x = use_machine(q);
			if (x & 1) v[1].push_back(min(n, j + B) - 1);
			res += sz - ((x + 1) / 2);
		}
		else
		{
			int x = use_machine(q);
			if (x & 1) v[0].push_back(min(n, j + B) - 1);
			res += x / 2;
		}
	}
	return res + v[0].size();
}

Compilation message

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:19:48: warning: comparison of integer expressions of different signedness: 'const long unsigned int' and 'int' [-Wsign-compare]
   19 |  for (; i < n && max(v[0].size(), v[1].size()) < B; i += 2)
      |                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 3 ms 344 KB Output is correct
8 Correct 5 ms 344 KB Output is correct
9 Correct 3 ms 344 KB Output is correct
10 Partially correct 5 ms 344 KB Output is partially correct
11 Incorrect 1 ms 344 KB Duplicate value 952 in the query array.
12 Halted 0 ms 0 KB -