답안 #303481

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
303481 2020-09-20T10:55:24 Z galca 버섯 세기 (IOI20_mushrooms) C++14
0 / 100
4 ms 308 KB
#include "mushrooms.h"

using namespace std;

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

	knownZeros.push_back(0);

	if (n <= 128) {
		for (int i = 1; i < n; i++) {
			int c = use_machine({ 0, i });
			if (c) {
				knownOnes.push_back(i);
			}
			else {
				knownZeros.push_back(i);
			}
		}
		return knownZeros.size();
	}

	for (int i = 1; i < 128; i++) {
		int c = use_machine({ 0, i });
		if (c) {
			knownOnes.push_back(i);
		}
		else {
			knownZeros.push_back(i);
		}
	}

	if (knownOnes.size() >= knownZeros.size()) {
		int totalZeros = knownZeros.size();
		for (int i = 128; i < n; i+=64) {
			vector<int> m;
			for (int j = 0; j < 64; j++) {
				if ((i + j) < n) {
					m.push_back(knownOnes[j]);
					m.push_back(i+j);
				}
			}
			int c = use_machine(m);
			if (c % 1) {
				++totalZeros;
				--c;
			}
			totalZeros += c / 2;
			m.erase(m.begin(), m.end());
		}
		return totalZeros;
	}
	else {
		int totalOnes = knownOnes.size();
		for (int i = 128; i < n; i += 64) {
			vector<int> m;
			for (int j = 0; j < 64; j++) {
				if ((i + j) < n) {
					m.push_back(knownZeros[j]);
					m.push_back(i + j);
				}
			}
			int c = use_machine(m);
			if (c % 1) {
				++totalOnes;
				--c;
			}
			totalOnes += c / 2;
			m.erase(m.begin(), m.end());
		}
		return n - totalOnes;
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Incorrect 4 ms 308 KB Answer is not correct.
7 Halted 0 ms 0 KB -