Submission #1364755

#TimeUsernameProblemLanguageResultExecution timeMemory
1364755ByeWorldCounting Mushrooms (IOI20_mushrooms)C++20
56.78 / 100
2 ms440 KiB
#include "mushrooms.h"
#include <bits/stdc++.h>
#pragma GCC optimize("O3", "Ofast")
#define ll long long
#define se second
#define fi first
#define pb push_back
#define lf (id<<1)
#define rg ((id<<1)|1)
#define md ((l+r)>>1)
#define USE use_machine
using namespace std;
typedef pair<int,int> pii;
typedef pair<pii,pii> ipii;
const int MAXN = 6e5+10;
const int MAXA = 5e4+10;
const int SQRT = 300;
const int INF = 2e9;
const int MOD = 1e9+87;
const int MOD2 = 1e9+7;
const int LOG = 30;

int n;
int count_mushrooms(int N) {
	n = N;
	vector<int> a = {0}, b;
	for(int i=1; i<=min(n-1, 200); i++){
		vector<int> m = {0, i};
		if(USE(m) == 1) b.pb(i);
		else a.pb(i);
	}
	if(n-1 <= 200){
		return a.size();
	}

	// cout << a.size() << ' '<< b.size()<< ' ' << "pp\n";
	int ans = a.size();
	if(b.size() < a.size()){//pake a
		int nw = 201;
		vector<int> m;
		int tot = 0; 
		while(nw <= n-1){
			if(m.empty()){
				m.pb(a[0]); tot = 1;
			}
			m.pb(nw); m.pb(a[tot]); 
			tot++; nw++;

			if(tot == a.size()){
				// cout << m.size() << " msiz\n";
				int ret = USE(m);
				ans += tot-1-ret/2; // ret/2 = b
				m.clear();
				tot = 0;
			}
		}
		if(!m.empty()){
				// cout << m.size() << " msiz\n";
			int ret = USE(m);
			ans += tot-1-ret/2; // ret/2 = b
		}

	} else {//pake b
		int nw = 201;
		vector<int> m;
		int tot = 0; 
		while(nw <= n-1){
			if(m.empty()){
				m.pb(b[0]); tot = 1;
			}
			m.pb(nw); m.pb(b[tot]); 
			tot++; nw++;

			if(tot == b.size()){
				int ret = USE(m);
				ans += ret/2; // ret/2 = b
				m.clear();
				tot = 0;
			}
		}
		if(!m.empty()){
			int ret = USE(m);
			ans += ret/2; // ret/2 = b
		}

	}

	return ans;
}
#Result Execution timeMemoryGrader output
Fetching results...