Submission #824851

#TimeUsernameProblemLanguageResultExecution timeMemory
824851NothingXDCounting Mushrooms (IOI20_mushrooms)C++17
88.28 / 100
8 ms508 KiB
#include "mushrooms.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

void debug_out(){cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T){
	cerr << H << ' ';
	debug_out(T...);
}

#define debug(...) cerr << "(" << #__VA_ARGS__ << "): ", debug_out(__VA_ARGS__)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define MP(x, y) make_pair(x, y)

const int maxn = 2e4 + 10;
const int sq = 70;

int count_mushrooms(int n) {
	vector<int> A, B;
	A.push_back(0);
	vector<int> ask = {0, 1};
	if (use_machine(ask)){
		B.push_back(1);
	}
	else{
		A.push_back(1);
	}
	if (n == 2) return A.size();
	ask = {0, 2};
	if (use_machine(ask)){
		B.push_back(2);
	}
	else{
		A.push_back(2);
	}
	bool flg = false;
	if (A.size() == 1){
		swap(A, B);
		flg = true;
	}
	for (int i = 3; i < n && A.size() < sq && B.size() < sq; i += 2){
		vector<int> ask;
		ask.push_back(A[0]);
		ask.push_back(i);
		ask.push_back(A[1]);
		if (i+1 < n) ask.push_back(i+1);
		int tmp = use_machine(ask);
		if ((tmp >> 1) & 1) B.push_back(i);
		else A.push_back(i);
		if (tmp & 1) B.push_back(i+1);
		else if (i + 1 < n) A.push_back(i+1);
	}
	if (A.size() < sq){
		swap(A, B);
		flg = !flg;
	}
	int sz = A.size();
	for (int i = A.size()+B.size(); i < n; i += sz){
		sz = A.size();
		//assert(0);
		vector<int> ask;
		for (int j = 0; j < A.size(); j++){
			ask.push_back(A[j]);
			if (i+j < n) ask.push_back(i+j);
		}
		int tmp = use_machine(ask);
		if (tmp % 2 == 0) A.push_back(ask.back());
		tmp = (tmp+1) / 2;
		for (int j = 0; j < tmp; j++){
			B.push_back(0);
		}
	}
	return (flg? B.size(): n-B.size());
} 

Compilation message (stderr)

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:70:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |   for (int j = 0; j < A.size(); j++){
      |                   ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...