Submission #304274

# Submission time Handle Problem Language Result Execution time Memory
304274 2020-09-21T05:33:24 Z galca Counting Mushrooms (IOI20_mushrooms) C++14
0 / 100
0 ms 256 KB
#include "mushrooms.h"

using namespace std;

int count_mushrooms(int n) {
	vector<int> knownZeros;
	vector<int> knownOnes;

	knownZeros.push_back(0);
	// find one more, or two 1s
	int i = 1;
	while ((knownZeros.size() < 2) && (knownOnes.size() < 2)) {
		int c = use_machine({ 0, i });
		if (c) {
			knownOnes.push_back(i);
		}
		else {
			knownZeros.push_back(i);
		}
		++i;
		if (i == n) {
			return knownZeros.size();
		}
	}

	vector<int> fours;
	bool isZero = false;

	if (knownZeros.size() == 2) {
		fours.push_back(knownZeros[0]);
		fours.push_back(0);
		fours.push_back(knownZeros[1]);
		fours.push_back(0);
		isZero = true;
	}
	else {
		fours.push_back(knownOnes[0]);
		fours.push_back(0);
		fours.push_back(knownOnes[1]);
		fours.push_back(0);
	}

	while ((knownZeros.size() < 100) && (knownOnes.size() < 100)) {
		if (i == n) {
			return knownZeros.size();
		}
		if (i == (n - 1)) {
			int c = use_machine({ 0, n - 1 });
			if (c) {
				return knownZeros.size();
			}
			else {
				knownZeros.size() + 1;
			}
		}
		fours[1] = i;
		fours[3] = i+1;
		int c = use_machine(fours);

		switch (c) {
			case 0:
				if (isZero) {
					knownZeros.push_back(i);
					knownZeros.push_back(i+1);
				}
				else {
					knownOnes.push_back(i);
					knownOnes.push_back(i + 1);
				}
				break;
			case 1:
				if (isZero) {
					knownZeros.push_back(i);
					knownOnes.push_back(i+1);
				}
				else {
					knownOnes.push_back(i);
					knownZeros.push_back(i + 1);
				}
				break;
			case 2:
				if (isZero) {
					knownOnes.push_back(i);
					knownZeros.push_back(i+1);
				}
				else {
					knownZeros.push_back(i);
					knownOnes.push_back(i + 1);
				}
				break;
			case 3:
				if (isZero) {
					knownOnes.push_back(i);
					knownOnes.push_back(i + 1);
				}
				else {
					knownZeros.push_back(i);
					knownZeros.push_back(i + 1);
				}
				break;
		}
		i += 2;
	}

	int totalZeros = knownZeros.size();

	while (i < n) {
		vector<int> m;
		if (knownOnes.size() >= knownZeros.size()) {
			
			for (int j = 0; j < knownOnes.size(); j++) {
				if ((i + j) < n) {
					m.push_back(knownOnes[j]);
					m.push_back(i + j);
				}
			}
			i += knownOnes.size();
			int c = use_machine(m);
			if (c & 1) {
				++totalZeros;
				--c;
				knownZeros.push_back(m[m.size() - 1]);
			}
			else {
				knownOnes.push_back(m[m.size() - 1]);
			}
			totalZeros += c / 2;
			
		}
		else {
			for (int j = 0; j < knownZeros.size(); j++) {
				if ((i + j) < n) {
					m.push_back(knownZeros[j]);
					m.push_back(i + j);
				}
			}
			i += knownZeros.size();
			int c = use_machine(m);
			if (c & 1) {
				++c;
				knownOnes.push_back(m[m.size() - 1]);
			}
			else {
				knownZeros.push_back(m[m.size() - 1]);
			}
			totalZeros += (m.size() - c) / 2;
			
		}
	}
	return totalZeros;
}

Compilation message

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:53:23: warning: value computed is not used [-Wunused-value]
   53 |     knownZeros.size() + 1;
      |     ~~~~~~~~~~~~~~~~~~^~~
mushrooms.cpp:111:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  111 |    for (int j = 0; j < knownOnes.size(); j++) {
      |                    ~~^~~~~~~~~~~~~~~~~~
mushrooms.cpp:131:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  131 |    for (int j = 0; j < knownZeros.size(); j++) {
      |                    ~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Incorrect 0 ms 256 KB Invalid value 4 in the query array.
3 Halted 0 ms 0 KB -