제출 #1298191

#제출 시각아이디문제언어결과실행 시간메모리
1298191orgiloogii버섯 세기 (IOI20_mushrooms)C++20
0 / 100
1 ms408 KiB
#include "mushrooms.h"
#include <bits/stdc++.h>
using namespace std;
//int count_mushrooms(int n) {
//	std::vector<int> m;
//	for (int i = 0; i < n; i++)
//		m.push_back(i);
//	int c1 = use_machine(m);
//	m = {0, 1};
//	int c2 = use_machine(m);
//	return c1+c2;
//}

int count_mushrooms(int n) {
//	vector <int> m;
	vector <int> as, bs;
	as.push_back(0);
	int i = 1;
	while (i < n && as.size() < 100 && bs.size() < 100) {
		if (use_machine({0, i}) == 1) {
			bs.push_back(i);
		}
		else {
			as.push_back(i);
		}
		i++;
	}
	if (i == n) {
		return as.size();
	}
	int ans = as.size();
	if (bs.size() == 100) {
		while (i < n) {
			int j = i + 1;
			vector <int> m;
			while (j < n && j <= i + 100) {
				m.push_back(bs[j - i - 1]);
				m.push_back(j);
				j++;
			}
			int c = use_machine(m);
			if (c % 2 == 1) {
				ans += 1;
			}
			ans += c / 2;
			i = j;
		}
		return ans;
	}
	while (i < n) {
		int j = i + 1;
		int cnt = 0;
		vector <int> m;
		while (j < n && j <= i + 100) {
			m.push_back(as[j - i - 1]);
			m.push_back(j);
			j++;
			cnt++;
		}
		int c = use_machine(m);
		if (c % 2 == 1) {
			c++;
			ans += cnt - (c / 2);
		}
		else {
			ans += cnt - (c / 2);
		}
		i = j;
	}
	return ans;
	
}
#Verdict Execution timeMemoryGrader output
Fetching results...