제출 #610377

#제출 시각아이디문제언어결과실행 시간메모리
610377JomnoiCounting Mushrooms (IOI20_mushrooms)C++17
87.94 / 100
10 ms336 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() < 2 and typeB.size() < 2 and i < N) {
		result = use_machine({0, i});
		if(result == 1) {
			typeB.push_back(i);
		}
		else {
			typeA.push_back(i);
		}
		i++;
	}
	while(typeA.size() < 140 and typeB.size() < 140 and i + 1 < N) {
		if(typeA.size() >= 2) {
			result = use_machine({typeA[0], i, typeA[1], i + 1});
			if(result == 0) {
				typeA.push_back(i);
				typeA.push_back(i + 1);
			}
			else if(result == 1) {
				typeA.push_back(i);
				typeB.push_back(i + 1);
			}
			else if(result == 2) {
				typeB.push_back(i);
				typeA.push_back(i + 1);
			}
			else {
				typeB.push_back(i);
				typeB.push_back(i + 1);
			}
		}
		else {
			result = use_machine({typeB[0], i, typeB[1], i + 1});
			if(result == 0) {
				typeB.push_back(i);
				typeB.push_back(i + 1);
			}
			else if(result == 1) {
				typeB.push_back(i);
				typeA.push_back(i + 1);
			}
			else if(result == 2) {
				typeA.push_back(i);
				typeB.push_back(i + 1);
			}
			else {
				typeA.push_back(i);
				typeA.push_back(i + 1);
			}
		}
		i += 2;
	}

	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();
}

컴파일 시 표준 에러 (stderr) 메시지

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