Submission #830742

#TimeUsernameProblemLanguageResultExecution timeMemory
830742amunduzbaevCounting Mushrooms (IOI20_mushrooms)C++17
0 / 100
0 ms208 KiB
#include "mushrooms.h"

#include "bits/stdc++.h"
using namespace std;

#define ar array
typedef long long ll;
//~ #define int ll

//~ const int B = 143;

int count_mushrooms(int n){
	int B = 1;
	for(int i=1;i<=n;i++){
		if(2 * i + (n + i - 1) / i < 2 * B + (n + B - 1) / B){
			B = i;
		}
	}
	
	vector<int> p[2];
	p[0].push_back(0);
	
	int last = 1;
	for(int i=1;i<n && max((int)p[0].size(), (int)p[1].size()) < B;i++){
		last++;
		if(use_machine({0, i})) p[1].push_back(i);
		else p[0].push_back(i);
	}
	
	ar<int, 2> cc {};
	cc[0] = p[0].size(), cc[1] = p[1].size();
	bool is = 1;
	if(p[0].size() < p[1].size()) is = 0;
	
	for(int i=last;i<n;){
		int j = min(i + B - 1, n);
		
		vector<int> qq;
		
		for(int k=i;k<j;k++){
			qq.push_back(p[is ^ 1][k - i]);
			qq.push_back(k);
		}
		
		qq.push_back(p[is ^ 1].back());
		
		int c = use_machine(qq) / 2;
		
		cc[is] += c, cc[is ^ 1] += (j - i - c);
		i = j;
	}
	
	return cc[0];
}
#Verdict Execution timeMemoryGrader output
Fetching results...