제출 #620528

#제출 시각아이디문제언어결과실행 시간메모리
6205288e7버섯 세기 (IOI20_mushrooms)C++17
56.64 / 100
19 ms316 KiB
//Challenge: Accepted
#include <bits/stdc++.h>
using namespace std;
#ifdef zisk
void debug(){cout << endl;}
template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);}
template<class T> void pary(T l, T r){
	while (l != r) cout << *l << " ", l++;
	cout << endl;
}
#else
#define debug(...) 0
#define pary(...) 0
#endif
#define ll long long
#define maxn 100005
#define pii pair<int, int>
#define ff first
#define ss second
#include "mushrooms.h"

int count_mushrooms(int n) {
	int c = max(2, int(sqrt(n)) * 3 / 4);	
	vector<int> a, b;
	vector<int> m;
	a.push_back(0);

	int i = 1;
	for (;i < n;i++) {
		m = {0, i};
		if (use_machine(m) == 0) {
			a.push_back(i);
		} else {
			b.push_back(i);
		}
		if (a.size() >= c || b.size() >= c) {
			i++;
			break;
		}
	}
	int sw = 0;
	if (b.size() >= c) {
		sw = 1;
		swap(a, b);
	}
	int ret = 0;
	for (;i < n;) {
		m.clear();
		int num = 0;
		for (int j = 0;j < c;j++) {
			m.push_back(a[j]);
			if (j != c - 1 && i < n) {
				num++;
				m.push_back(i);
				i++;
			}
		}
		if (sw) ret += (use_machine(m)/2);
		else ret += num - (use_machine(m)/2);
	}
	if (sw) ret += b.size();
	else ret += a.size();
	return ret;
}

컴파일 시 표준 에러 (stderr) 메시지

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:36:16: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   36 |   if (a.size() >= c || b.size() >= c) {
      |       ~~~~~~~~~^~~~
mushrooms.cpp:36:33: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   36 |   if (a.size() >= c || b.size() >= c) {
      |                        ~~~~~~~~~^~~~
mushrooms.cpp:42:15: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   42 |  if (b.size() >= c) {
      |      ~~~~~~~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...