Submission #346059

#TimeUsernameProblemLanguageResultExecution timeMemory
346059Chayanin_KCounting Mushrooms (IOI20_mushrooms)C++17
0 / 100
1 ms384 KiB
#include "mushrooms.h"
#include <bits/stdc++.h>

using namespace std;

int count_mushrooms(int n) {	

	vector <int> A, B, send;

	int res, nowi = 1, cnta = 1, cnt = 0;

	A.push_back(0);

	while(nowi < n){

	if(A.size() >= B.size()){
		cnt = 0;
		send.clear();
		for(int i = 0; i < A.size() && nowi < n; i++){
			send.push_back(A[i]);
			send.push_back(nowi);
			nowi++;
			cnt++;
		}
		res = use_machine(send);
		if(res%2==1){
			B.push_back(nowi-1);
		}
		else{	
			cnta += cnt - ((res+1) / 2);
			A.push_back(nowi-1);
		}
	}
	else{
		send.clear();
		for(int i = 0; i < B.size() && nowi < n; i++){
			send.push_back(B[i]);
			send.push_back(nowi);
			nowi++;
		}
		res = use_machine(send);
		if(res%2==1){
			A.push_back(nowi-1);
			cnta += (res+1) / 2;
		}
		else{
			B.push_back(nowi-1);
		}
	}

	}

	return cnta;

}

Compilation message (stderr)

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