Submission #1078177

# Submission time Handle Problem Language Result Execution time Memory
1078177 2024-08-27T13:34:56 Z Faisal_Saqib Rarest Insects (IOI22_insects) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
void move_inside(int i);
void move_outside(int i);
int press_button();
map<vector<int>,int> store;
set<int> cur,machine;
void add(int&i)
{
	i--;
	cur.insert(i);
}
void rem(int&i)
{
	i--;
	cur.erase();
}
void khatam()
{
	cur.clear();
}
int ask()
{
	vector<int> vec(begin(cur),end(cur));
	if(store.find(vec)!=store.end())return store[vec];
	for(auto&i:cur)
		if(machine.find(i)==machine.end())
			move_inside(i);
	for(auto&j:machine)
		if(cur.find(i)==cur.end())
			move_outside(j);
	machine=cur;
	store[vec]=press_button();
	return store[vec];
}
int min_cardinality(int n)
{
	vector<int> heads={1};
	add(1);
	for(int i=2;i<=n;i++)
	{
		add(i);
		if(ask()==1)
			heads.push_back(i);
		else
			rem(i);
	}
	int sz=heads.size(),np=n;
	int sm=0;
	while(1)
	{
		int mid=(np)/sz;
		khatam();
		for(int i=1;i<=n and sm<(sz*mid);i++)
		{
			if(i<=mid)
			{
				add(i);
				sm++;
			}
			else
			{				
				add(i);
				if(ask()>mid)
				{
					rem(j);
				}
				else
				{
					sm++;
				}
			}
		}
		if(sm==((sz*mid)))
		{
			return mid; // this is the answer
		}
		else{
			np=sm;
		}
	}
	return -1;
}

Compilation message

insects.cpp: In function 'void rem(int&)':
insects.cpp:16:12: error: no matching function for call to 'std::set<int>::erase()'
   16 |  cur.erase();
      |            ^
In file included from /usr/include/c++/10/set:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:87,
                 from insects.cpp:1:
/usr/include/c++/10/bits/stl_set.h:654:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::erase(std::set<_Key, _Compare, _Alloc>::const_iterator) [with _Key = int; _Compare = std::less<int>; _Alloc = std::allocator<int>; std::set<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::const_iterator; std::set<_Key, _Compare, _Alloc>::const_iterator = std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::const_iterator]'
  654 |       erase(const_iterator __position)
      |       ^~~~~
/usr/include/c++/10/bits/stl_set.h:654:7: note:   candidate expects 1 argument, 0 provided
/usr/include/c++/10/bits/stl_set.h:684:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::size_type std::set<_Key, _Compare, _Alloc>::erase(const key_type&) [with _Key = int; _Compare = std::less<int>; _Alloc = std::allocator<int>; std::set<_Key, _Compare, _Alloc>::size_type = long unsigned int; std::set<_Key, _Compare, _Alloc>::key_type = int]'
  684 |       erase(const key_type& __x)
      |       ^~~~~
/usr/include/c++/10/bits/stl_set.h:684:7: note:   candidate expects 1 argument, 0 provided
/usr/include/c++/10/bits/stl_set.h:706:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::erase(std::set<_Key, _Compare, _Alloc>::const_iterator, std::set<_Key, _Compare, _Alloc>::const_iterator) [with _Key = int; _Compare = std::less<int>; _Alloc = std::allocator<int>; std::set<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::const_iterator; std::set<_Key, _Compare, _Alloc>::const_iterator = std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::const_iterator]'
  706 |       erase(const_iterator __first, const_iterator __last)
      |       ^~~~~
/usr/include/c++/10/bits/stl_set.h:706:7: note:   candidate expects 2 arguments, 0 provided
insects.cpp: In function 'int ask()':
insects.cpp:30:15: error: 'i' was not declared in this scope
   30 |   if(cur.find(i)==cur.end())
      |               ^
insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:39:6: error: cannot bind non-const lvalue reference of type 'int&' to an rvalue of type 'int'
   39 |  add(1);
      |      ^
insects.cpp:8:14: note:   initializing argument 1 of 'void add(int&)'
    8 | void add(int&i)
      |          ~~~~^
insects.cpp:66:10: error: 'j' was not declared in this scope
   66 |      rem(j);
      |          ^