Submission #1243812

#TimeUsernameProblemLanguageResultExecution timeMemory
1243812chinesegenius69420Counting Mushrooms (IOI20_mushrooms)C++20
25 / 100
27 ms420 KiB
#include <bits/stdc++.h>
#include "mushrooms.h"
using namespace std;

int count_mushrooms(int n) {
	int ans = 1;
	int posA = -1;
	vector<int> pb;
	int lasti;
	if(n < 4){
		for(int i = 1; i < n; i++){
			ans += use_machine({0, i}) ^ 1;
		}
		return ans;
	}
	lasti = 1;
	for(int i = 1; i < min(n, 3); i++){
		lasti++; 
		if(use_machine({0, i})){
			pb.push_back(i);
			continue;	
		}
		ans++;
		posA = i;
		break;
	}
	int pos1, pos2;
	bool haya = false;
	if(posA != -1){
		pos1 = 0;
		pos2 = posA;
		haya = true;
	} else {
		pos1 = pb[0];
		pos2 = pb[1];
	}
	if((n - lasti) % 2){
		ans += (use_machine({0, lasti}) ? 0 : 1);
		lasti++;
	}
	for(int i = lasti; i < n; i += 2){
		int x = use_machine({pos1, i, pos2, i + 1});
		if(haya){
			if(!x) ans += 2;
			else if(x < 3) ans += 1;
			continue;
		}
		if(x == 3) ans += 2;
		else if(x) ans += 1;
	}
	return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...