Submission #305868

#TimeUsernameProblemLanguageResultExecution timeMemory
305868myungwooCounting Mushrooms (IOI20_mushrooms)C++17
92.24 / 100
9 ms384 KiB
#include <bits/stdc++.h>
#include "mushrooms.h"
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)

int count_mushrooms(int N)
{
	const int K = 73;
	int add = 0;
	vector <int> arr[2];
	arr[0] = {0};
	for (int i=1;i<N;i++){
		if (arr[0].size() > arr[1].size() && arr[0].size() >= K){
			vector <int> test;
			for (int j=0;j<arr[0].size()&&i+j<N;j++){
				test.push_back(arr[0][j]);
				test.push_back(i+j);
			}
			int res = use_machine(test);
			add += test.size()/2-1;
			add -= res>>1;
			i += test.size()/2-1;
			arr[res&1].push_back(test.back());
		}
		else if (arr[1].size() >= K){
			vector <int> test;
			for (int j=0;j<arr[1].size()&&i+j<N;j++){
				test.push_back(arr[1][j]);
				test.push_back(i+j);
			}
			int res = use_machine(test);
			add += res>>1;
			i += test.size()/2-1;
			arr[res&1^1].push_back(test.back());
		}
		else if (i+1 < N && arr[0].size() > 1){
			int res = use_machine({arr[0][0], i, arr[0][1], i+1});
			arr[res>>1&1].push_back(i);
			arr[res&1].push_back(++i);
		}else if (i+1 < N && arr[1].size() > 1){
			int res = use_machine({arr[1][0], i, arr[1][1], i+1});
			arr[res>>1&1^1].push_back(i);
			arr[res&1^1].push_back(++i);
		}
		else arr[use_machine({0, i})].push_back(i);
	} 
	return arr[0].size() + add;
}

Compilation message (stderr)

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:16:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |    for (int j=0;j<arr[0].size()&&i+j<N;j++){
      |                 ~^~~~~~~~~~~~~~
mushrooms.cpp:28:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |    for (int j=0;j<arr[1].size()&&i+j<N;j++){
      |                 ~^~~~~~~~~~~~~~
mushrooms.cpp:35:11: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   35 |    arr[res&1^1].push_back(test.back());
      |        ~~~^~
mushrooms.cpp:43:14: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   43 |    arr[res>>1&1^1].push_back(i);
      |        ~~~~~~^~
mushrooms.cpp:44:11: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   44 |    arr[res&1^1].push_back(++i);
      |        ~~~^~
#Verdict Execution timeMemoryGrader output
Fetching results...