Submission #610368

#TimeUsernameProblemLanguageResultExecution timeMemory
610368JomnoiCounting Mushrooms (IOI20_mushrooms)C++17
57.22 / 100
12 ms360 KiB
#include <bits/stdc++.h>
#include "mushrooms.h"
using namespace std;

int result;
vector <int> x;
vector <int> typeA, typeB;

int count_mushrooms(int N) {
	typeA.push_back(0);
	int i = 1;
	while(typeA.size() < 140 and typeB.size() < 140 and i < N) {
		result = use_machine({0, i});
		if(result == 1) {
			typeB.push_back(i);
		}
		else {
			typeA.push_back(i);
		}
		i++;
	}

	int numberofA = 0, cnt;
	while(i < N) {
		if(typeA.size() > typeB.size()) {
			x.clear();
			cnt = -1;
			for(int j = 0; j < typeA.size() and i < N; j++) {
				x.push_back(typeA[j]);
				x.push_back(i++);
				cnt++;
			}

			result = use_machine(x);

			numberofA += cnt - result / 2;
			if(result % 2 == 0) {
				typeA.push_back(i - 1);
			}
			else {
				typeB.push_back(i - 1);
			}
		}
		else {
			x.clear();
			for(int j = 0; j < typeB.size() and i < N; j++) {
				x.push_back(typeB[j]);
				x.push_back(i++);
			}

			result = use_machine(x);

			numberofA += result / 2;
			if(result % 2 == 1) {
				typeA.push_back(i - 1);
			}
			else {
				typeB.push_back(i - 1);
			}
		}
	}
	return numberofA + typeA.size();
}

Compilation message (stderr)

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:28:21: 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 < typeA.size() and i < N; j++) {
      |                   ~~^~~~~~~~~~~~~~
mushrooms.cpp:46:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |    for(int j = 0; j < typeB.size() and i < N; j++) {
      |                   ~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...