제출 #390566

#제출 시각아이디문제언어결과실행 시간메모리
390566AdOjis485버섯 세기 (IOI20_mushrooms)C++17
0 / 100
1 ms200 KiB
#include "mushrooms.h"
#include <iostream>
using namespace std;

int count_mushrooms(int n)
{
	vector<int> type(n, -1);
	vector<int> a = {0};
	vector<int> b;
	type[0] = 0;
	
	int sqrt;
	for(int i = 1; i * i < n; i ++)
	{
		sqrt = i;
		type[i] = use_machine({0, i});
		if(type[i] == 0) a.push_back(i);
		else b.push_back(i);
	}

	int ans = a.size();
	bool typea = true;
	if(b.size() > a.size())
	{
		a = b;
		typea = false;
	}
	int n2 = a.size();
	vector<int> c(2 * n2 - 1);
	for(int i = 0; i < a.size(); i ++) c[2 * i] = a[i];

	int j = sqrt + 1;
	while(j < n)
	{
		for(int i = 1; i < n2; i ++, j ++)
		{
			if(j >= n)
			{
				c.pop_back();
				c.pop_back();
			} 
			else c[2 * i - 1] = j;
		}
		// for(auto el : c) cerr << el << " ";
		// cerr << ' ';
		if(typea) ans += c.size() - use_machine(c) / 2;
		else ans += use_machine(c) / 2;
		// cerr << ans << '\n';

	}
	
	return ans;
}

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

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:30:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |  for(int i = 0; i < a.size(); i ++) c[2 * i] = a[i];
      |                 ~~^~~~~~~~~~
mushrooms.cpp:32:6: warning: 'sqrt' may be used uninitialized in this function [-Wmaybe-uninitialized]
   32 |  int j = sqrt + 1;
      |      ^
#Verdict Execution timeMemoryGrader output
Fetching results...