Submission #1021636

#TimeUsernameProblemLanguageResultExecution timeMemory
1021636HappyCapybaraCounting Mushrooms (IOI20_mushrooms)C++17
80.71 / 100
6 ms1124 KiB
#include "mushrooms.h"
#include<bits/stdc++.h>
using namespace std;

int count_mushrooms(int n) {
	vector<int> as = {0}, bs;
	int i = 1, res = 1;
	while (i < n){
		vector<int> m;
		if (as.size() >= bs.size()){
			int j = 0;
			while (i < n && j < as.size()){
				m.push_back(as[j]);
				m.push_back(i);
				i++;
				j++;
			}
			int x = use_machine(m);
			if (x % 2) bs.push_back(m.back());
			else {
				as.push_back(m.back());
				res++;
			}
			res += (m.size()/2 - x/2 - 1);
			if (x/2 == 0){
				for (int k=1; k<m.size()-1; k+=2) as.push_back(m[k]);
			}
			if ((x/2)*2 == m.size()-2){
				for (int k=1; k<m.size()-1; k+=2) bs.push_back(m[k]);
			}
		}
		else {
			int j = 0;
			while (i < n && j < bs.size()){
				m.push_back(bs[j]);
				m.push_back(i);
				i++;
				j++;
			}
			int x = use_machine(m);
			if (x % 2){
				as.push_back(m.back());
				res++;
			}
			else bs.push_back(m.back());
			res += (x/2);
			if (x/2 == 0){
				for (int k=1; k<m.size()-1; k+=2) bs.push_back(m[k]);
			}
			if ((x/2)*2 == m.size()-2){
				for (int k=1; k<m.size()-1; k+=2) as.push_back(m[k]);
			}
		}
	}
	return res;
}

Compilation message (stderr)

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:12:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |    while (i < n && j < as.size()){
      |                    ~~^~~~~~~~~~~
mushrooms.cpp:26:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     for (int k=1; k<m.size()-1; k+=2) as.push_back(m[k]);
      |                   ~^~~~~~~~~~~
mushrooms.cpp:28:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |    if ((x/2)*2 == m.size()-2){
      |        ~~~~~~~~^~~~~~~~~~~~~
mushrooms.cpp:29:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |     for (int k=1; k<m.size()-1; k+=2) bs.push_back(m[k]);
      |                   ~^~~~~~~~~~~
mushrooms.cpp:34:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |    while (i < n && j < bs.size()){
      |                    ~~^~~~~~~~~~~
mushrooms.cpp:48:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |     for (int k=1; k<m.size()-1; k+=2) bs.push_back(m[k]);
      |                   ~^~~~~~~~~~~
mushrooms.cpp:50:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |    if ((x/2)*2 == m.size()-2){
      |        ~~~~~~~~^~~~~~~~~~~~~
mushrooms.cpp:51:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |     for (int k=1; k<m.size()-1; k+=2) as.push_back(m[k]);
      |                   ~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...