Submission #1234067

#TimeUsernameProblemLanguageResultExecution timeMemory
1234067madamadam3Counting Mushrooms (IOI20_mushrooms)C++20
56.64 / 100
3 ms504 KiB
#include "mushrooms.h"
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
	#define dbg(x) (cout << (x))
#else
	#define dbg(x)
#endif

using vi =vector<int>;
#define pb push_back
#define FOR(i, a, b) for (int i = a; i < b; i++)

int count_mushrooms(int n) {
	vi isa(n, 0); isa[0] = 1;

	int top_it = min(n, 200);
	for (int i = 1; i < top_it; i++) {
		isa[i] = 1 - use_machine(vi({0, i}));
	}

	if (top_it == n) return accumulate(isa.begin(), isa.end(), 0);
	int tl_a = accumulate(isa.begin(), isa.end(), 0);
	bool using_dark = tl_a < 100;

	int first_light = 0, first_dark = 0; while (isa[first_dark]) first_dark++;
	vi filter_base(199, using_dark ? first_dark : first_light);
	int cur_pos = 0;
	for (int i = 0; i < 200 && cur_pos < 200; i++) {
		if (isa[i] == using_dark) continue;
		filter_base[cur_pos] = i;
		cur_pos += 2;
	}

	for (int i = 200; i < n; i += 99) {
		int spots = min(99, n - i);
		vi filter(filter_base.begin(), filter_base.end());

		int ps = 1;
		for (int j = i; j < i + spots; j++) {
			filter[ps] = j;
			ps += 2;
		}

		filter.resize(spots*2 + 1);
		int tl_non = use_machine(filter) / 2;
		if (using_dark) {
			tl_a += tl_non;
		} else {
			tl_a += spots - tl_non;
		}
	}

	return tl_a;
}
#Verdict Execution timeMemoryGrader output
Fetching results...