Submission #1046742

#TimeUsernameProblemLanguageResultExecution timeMemory
1046742mariaclaraCounting Mushrooms (IOI20_mushrooms)C++17
55.53 / 100
6 ms444 KiB
#include "mushrooms.h"
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define mk make_pair 
#define pb push_back
#define fr first 
#define sc second

int C = 80;
int count_mushrooms(int n) {
	vector<int> A, B;

	A.pb(0);
	for(int i = 1; i < n; i++) {
		if(use_machine({0,i}) == 0) A.pb(i);
		else B.pb(i);
		if(sz(A) >= C or sz(B) >= C) break;
	}

	int use = 0;
	if(sz(A) < sz(B)) use = 1;

	int ans = sz(A);
	for(int i = sz(A) + sz(B); i < n; i+=C) {
		if(use == 0) {
			vector<int> q;
			for(int j = i; j < min(n,i+C); j++)
				q.pb(A[j-i]), q.pb(j);

			int x = use_machine(q);
			x = sz(q) - 1 - x; // número de posições que são iguais
			ans += (x+1)/2;
		}
		else {
			vector<int> q;
			for(int j = i; j < min(n,i+C); j++)
				q.pb(B[j-i]), q.pb(j);

			int x = use_machine(q);
			// número de posições que são diferentes
			ans += (x+1)/2;
		}
	}

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