제출 #1078174

#제출 시각아이디문제언어결과실행 시간메모리
1078174Muhammad_Aneeq드문 곤충 (IOI22_insects)C++17
25 / 100
2561 ms153824 KiB
void move_inside(int i);
void move_outside(int i);
int press_button();
#include <iostream>
#include <vector>
#include <map>
#include <set>
using namespace std;
set<int>ind;
map<set<int>,int>d;
int ask()
{
	if (d.find(ind)!=d.end())
		return d[ind];
	d[ind]=press_button();
	return d[ind];
}
int min_cardinality(int N)
{
	int colors=0;
	for (int i=0;i<N;i++)
	{
		move_inside(i);
		ind.insert(i);
		if (ask()==2)
		{
			move_outside(i);
			ind.erase(i);
		}
		else
			colors++;
	}
	set<int>ni;
	for (int i=0;i<N;i++)
		if (ind.find(i)==ind.end())
			ni.insert(i);
	if (colors==1)
		return N;
	int st=1,en=N/colors+1;
	while (st+1<en)
	{
		int mid=(st+en)/2;
		for (auto i:ni)
		{
			if (ind.size()==colors*mid)
				break;
			move_inside(i);
			ind.insert(i);
			if (ask()>mid)
			{
				move_outside(i);
				ind.erase(i);
			}
		}
		if (ind.size()==mid*colors)
		{
			for (auto i:ind)
				ni.erase(i);
			st=mid;
		}
		else
		{
			en=mid;
			ni.clear();
			for (auto i:ind)
			{
				ni.insert(i);
				move_outside(i);
			}
			ind.clear();
		}
	}
	return st;
}

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

insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:45:18: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   45 |    if (ind.size()==colors*mid)
      |        ~~~~~~~~~~^~~~~~~~~~~~
insects.cpp:55:17: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   55 |   if (ind.size()==mid*colors)
      |       ~~~~~~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...