Submission #824900

#TimeUsernameProblemLanguageResultExecution timeMemory
824900NothingXDCounting Mushrooms (IOI20_mushrooms)C++17
87.94 / 100
9 ms336 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 = 140;

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);
	}
	int sz;
	int cnta = 0, cntb = 0;
	for (int i = A.size()+B.size(); i < n; i += sz){
		//debug(i);
		if (A.size() < B.size()){
			swap(A, B);
			swap(cnta, cntb);
			flg = !flg;
		}
		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);
	//	debug(tmp);
		if (i + sz-1 < n && tmp % 2 == 0){
			A.push_back(ask.back());
			debug(flg, ask.back());
		}
		else if (i + sz-1 < n){
			B.push_back(ask.back());
			debug(!flg, ask.back());
		}
		cntb += tmp/2;
		cnta += min(sz-1, n-i) - tmp/2;
		//debug(flg, A.size(), cnta, B.size(), cntb);
	}
	return (flg? B.size() + cntb: A.size() + cnta);
} 

Compilation message (stderr)

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