Submission #959385

# Submission time Handle Problem Language Result Execution time Memory
959385 2024-04-08T06:30:48 Z The_Samurai Counting Mushrooms (IOI20_mushrooms) C++17
0 / 100
2 ms 448 KB
#include "mushrooms.h"
#include "bits/stdc++.h"
using namespace std;

int count_mushrooms(int n) {
	vector<int> zeros = {0};
	const int cnt = 45, b = 635;
	int l, r;
	for (l = 1, r = b; l < n; l += b, r += b) {
		r = min(r, n - 1);
		vector<int> v = {0};
		for (int i = l; i <= r; i++) v.emplace_back(i);
		int x = use_machine(v);
		if (x == 0) {
			for (int i = l; i <= r; i++) zeros.emplace_back(i);
			break;
		}
		if (x == 1) {
			for (int i = l; i <= r; i++) {
				if (use_machine({0, i})) break;
				zeros.emplace_back(i);
			}
			continue;
		}
		while (zeros.size() < cnt) {
			if (zeros.back() + 1 > r) break;
			int lx = max(l, zeros.back() + 1), rx = r, best = -1;
			int start = max(l, zeros.back() + 1);
			bool found = false;
			if (use_machine({0, lx}) == 0) {
				zeros.emplace_back(lx);
				continue;
			}
			lx++;
			// cout << lx << ' ' << rx << endl;
			while (lx <= rx) {
				int mid = (lx + rx) >> 1;
				v = {0};
				for (int i = start; i <= mid; i++) v.emplace_back(i);
				x = use_machine(v);
				// cout << '\t' << mid << ' ' << x << endl;
				if (x >= 2) {
					rx = mid - 1;
					best = mid;
				} else if (x == 0) {
					for (int i = start; i <= mid; i++) zeros.emplace_back(i);
					found = true;
					break;
				} else {
					lx = mid + 1;
				}
			}
			if (found) continue;
			if (best == -1) break;
			zeros.emplace_back(best);
		}
		if (zeros.size() >= cnt) break;
	}
	// for (int x: zeros) cout << x << ' ';
	// cout << endl;
	if (zeros.size() < cnt) return zeros.size();
	vector<int> unused;
	for (int i = r + 1; i < n; i++) unused.emplace_back(i);
	int ans = zeros.size();
	while (!unused.empty()) {
		int ln = min(unused.size(), zeros.size());
		vector<int> v;
		for (int i = 0; i < ln; i++) {
			v.emplace_back(zeros[i]);
			v.emplace_back(unused.back());
			unused.pop_back();
		}
		ans += ln - (use_machine(v) + 1) / 2;
	}
	return ans;
}

// 0 -> 3
// 2 -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Incorrect 2 ms 448 KB Answer is not correct.
6 Halted 0 ms 0 KB -