제출 #620658

#제출 시각아이디문제언어결과실행 시간메모리
6206588e7버섯 세기 (IOI20_mushrooms)C++17
80.71 / 100
13 ms456 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)));	
	vector<int> a, b;
	vector<int> m;
	a.push_back(0);

	int i = 1, ret = 0, sw = 0;
	for (;i < n;) {
		m.clear();
		vector<int> tmp;
		if (a.size() >= b.size()) {
			tmp = a;
			sw = 0;
		} else {
			tmp = b;
			sw = 1;
		}
		int num = 0;
		for (int j = 0;j < tmp.size();j++) {
			m.push_back(tmp[j]);
			if (i < n) {
				num++;
				m.push_back(i);
				i++;
			}
		}
		//pary(m.begin(), m.end());
		int res = use_machine(m);
		if (num == tmp.size()) {
			//debug("end", sw, res%2);
			int bb = sw ^ (res%2);
			if (bb) {
				b.push_back(i-1);
			} else {
				a.push_back(i-1);
				ret--;
			}
			
		}
		if (sw) ret += (res+1)/2;
		else ret += num - ((res+1)/2);
	}
	ret += a.size();
	return ret;
}

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

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:40:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |   for (int j = 0;j < tmp.size();j++) {
      |                  ~~^~~~~~~~~~~~
mushrooms.cpp:50:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |   if (num == tmp.size()) {
      |       ~~~~^~~~~~~~~~~~~
mushrooms.cpp:23:6: warning: unused variable 'c' [-Wunused-variable]
   23 |  int c = max(2, int(sqrt(n)));
      |      ^
#Verdict Execution timeMemoryGrader output
Fetching results...