Submission #1365543

#TimeUsernameProblemLanguageResultExecution timeMemory
1365543ByeWorldCounting Mushrooms (IOI20_mushrooms)C++20
80.71 / 100
2 ms460 KiB
#include "mushrooms.h"
#include <bits/stdc++.h>
#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;
vector<int> a[2];

int count_mushrooms(int N) {
	n = N;
	a[1] = {0};

	int ans = 1, nw = 1;

	while(nw <= n-1){
		int tot = 0; 
		vector<int> m;

		if(a[0].size() < a[1].size()){//pake a
			for(int i=0; i<a[1].size(); i++){
				m.pb(a[1][i]); m.pb(nw++); 
				tot++;

				if(nw == n) break;
			}

			int ret = USE(m);
			ans += tot-1-ret/2; // ret/2 = B
			if(ret%2 == 1) a[0].pb(m.back()); // ada b di depan
			else ans++, a[1].pb(m.back());

		} else {//pake b
			for(int i=0; i<a[0].size(); i++){
				m.pb(a[0][i]); m.pb(nw++); 
				tot++;

				if(nw == n) break;
			}

			int ret = USE(m);
			ans += ret/2; // ret/2 = A
			if(ret%2 == 1) ans++, a[1].pb(m.back()); // ada b di depan
			else a[0].pb(m.back());
				
		}
	}

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