Submission #605441

#TimeUsernameProblemLanguageResultExecution timeMemory
605441TigryonochekkCounting Mushrooms (IOI20_mushrooms)C++17
0 / 100
0 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;
	int c = a.size();
	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());
	}
	else {
		a.push_back(m.back());
	}
	ans += t - s - u / 2;
}

void execB(int s, int t) {
	if (s == t) return;
	int c = b.size();
	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 / 2;
}

int count_mushrooms(int nigga) {
	n = nigga;
	if (n <= 0) {
		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 = 5;
	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);
		}
	}

	int s = x;
	while (s < n) {
		if (a.size() >= b.size()) {
			int t = min(n, s + (int)a.size());
			execA(s, t);
			s = t;
		}
		else {
			int t = min(n, s + (int)b.size());
			execB(s, t);
			s = t;
		}
		//cout << s << endl;
	}
	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

*/

Compilation message (stderr)

mushrooms.cpp: In function 'void execA(int, int)':
mushrooms.cpp:59:6: warning: unused variable 'c' [-Wunused-variable]
   59 |  int c = a.size();
      |      ^
mushrooms.cpp: In function 'void execB(int, int)':
mushrooms.cpp:79:6: warning: unused variable 'c' [-Wunused-variable]
   79 |  int c = b.size();
      |      ^
#Verdict Execution timeMemoryGrader output
Fetching results...