Submission #606350

#TimeUsernameProblemLanguageResultExecution timeMemory
606350TigryonochekkCounting Mushrooms (IOI20_mushrooms)C++17
0 / 100
2 ms208 KiB
#include <iostream>
#include "mushrooms.h"
#include <vector>
#define ll long long
using namespace std;

int n;
vector<int> a = { 0 }, b;
int ans = 1;

void findA(int p, int q, int i) {
	int u = use_machine({ p, i, q, i + 1 });
	if (u == 0) {
		a.push_back(i);
		a.push_back(i + 1);
		ans += 2;
	}
	else if (u == 1) {
		b.push_back(i);
		a.push_back(i + 1);
		ans++;
	}
	else if (u == 2) {
		a.push_back(i);
		b.push_back(i + 1);
		ans++;
	}
	else {
		b.push_back(i);
		b.push_back(i + 1);
	}
}

void findB(int p, int q, int i) {
	int u = use_machine({ p, i, q, i + 1 });
	if (u == 0) {
		b.push_back(i);
		b.push_back(i + 1);
	}
	else if (u == 1) {
		a.push_back(i);
		b.push_back(i + 1);
		ans++;
	}
	else if (u == 2) {
		b.push_back(i);
		a.push_back(i + 1);
		ans++;
	}
	else {
		a.push_back(i);
		a.push_back(i + 1);
		ans += 2;
	}
}

void execA(int s, int t) {
	if (s == t) return;
	vector<int> m;
	int j = 0;
	for (int i = s; i < t; i++) {
		m.push_back(a[j]);
		m.push_back(i);
		j++;
	}
	int u = use_machine(m);
	if (u % 2 == 1) {
		b.push_back(m.back());
		u--;
	}
	else {
		a.push_back(m.back());
		ans++;
	}
	ans += t - s - u / 2;
}

void execB(int s, int t) {
	if (s == t) return;
	vector<int> m;
	int j = 0;
	for (int i = s; i < t; i++) {
		m.push_back(b[j]);
		m.push_back(i);
		j++;
	}
	int u = use_machine(m);
	if (u % 2 == 0) {
		b.push_back(m.back());
	}
	else {
		a.push_back(m.back());
		ans++;
		u--;
	}
	ans += u / 2;
}

int count_mushrooms(int nigga) {
	n = nigga;
	if (n <= 450) {
		for (int i = 1; i < n - 1; i += 2) {
			ans += 2 - use_machine({ i, 0, i + 1 });
		}
		if (n % 2 == 0) {
			ans += 1 - use_machine({ n - 1, 0 });
		}
		return ans;
	}
	int x = 119;
	if (!use_machine({ 0, 1 })) {
		a.push_back(1);
		ans++;
	}
	else {
		b.push_back(1);
	}
	if (!use_machine({ 0, 2 })) {
		a.push_back(2);
		ans++;
	}
	else {
		b.push_back(2);
	}
	if (a.size() >= 2) {
		for (int i = 3; i < x; i += 2) {
			findA(a[0], a[1], i);
		}
	}
	else {
		for (int i = 3; i < x; i += 2) {
			findB(b[0], b[1], i);
		}
	}
	//cout << ans << endl;
	int s = x;
	while (s < n) {
		if (a.size() >= b.size()) {
			int t = min(n, s + (int)a.size());
			execA(s, t);
			//cout << " a " << s << " " << t << " " << ans << endl;
			s = t;
		}
		else {
			int t = min(n, s + (int)b.size());
			execB(s, t);
			//cout << " b " << s << " " << t << " " << ans << endl;
			s = t;
		}
	}
	return ans;
}

/*
12 
0 1 0 1 1 0 0 0 1 1 1 1 

19	
0 1 1 1 1 0 1 1 0 0 0 0 0 1 1 1 0 1 0

*/
#Verdict Execution timeMemoryGrader output
Fetching results...