Submission #830676

# Submission time Handle Problem Language Result Execution time Memory
830676 2023-08-19T09:13:57 Z caganyanmaz Rarest Insects (IOI22_insects) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#include "insects.h"
#define pb push_back
using namespace std;


constexpr static int BLOCK = 50;

int n;
set<int> basis;

bool check(int val)
{
	vector<int> ci;
	for (int i = 0; i < n; i++)
	{
		if (basis.find(i) != basis.end())
			continue;
		move_inside(i);
		ci.pb(i);
		if (press_button() > val)
		{
			move_outside(i);
			ci.pop_back();
		}
	}
	return ci.size() == (val-1) * basis.size();
}

int test_a()
{
	int l = 1, r = 1 + n / basis.size();
	while (r - l > 1)
	{
		int m = l+r>>1;
		if(check(m))
			l = m;
		else
			r = m;
	}
	return l;
}

vector<int> bs;
set<int> machine;

int get_min(int l, int r, vector<int>& v)
{
	if (r - l == 1)
	{
		debug(l, v);
		return v.size()+1;
	}
	int m = l+r>>1;
	for (int i = l; i < m; i++)
	{
		if (machine.find(bs[i]) != machine.end())
			continue;
		machine.insert(bs[i]);
		move_inside(bs[i]);
	}
	for (int i = m; i < r; i++)
	{
		if (machine.find(bs[i]) == machine.end())
			continue;
		machine.erase(bs[i]);
		move_outside(bs[i]);
	}
	vector<int> lv, rv;
	for (int i : v)
	{
		move_inside(i);
		if (press_button() > 1)
			lv.pb(i);
		else
			rv.pb(i);
		move_outside(i);
	}
	int lres = get_min(l, m, lv);
	int rres = get_min(m, r, rv);
	return min(lres, rres);

}

int test_b()
{
	for (int i : basis)
	{
		bs.pb(i);
		machine.insert(i);
	}
	vector<int> v;
	for (int i = 0; i < n; i++)
		if (basis.find(i) == basis.end())
			v.pb(i);
	return get_min(0, bs.size(), v);
}

int min_cardinality(int N)
{
	n = N;
	for (int i = 0; i < n; i++)
	{
		move_inside(i);
		if (press_button() > 1)
			move_outside(i);
		else
			basis.insert(i);
	}	
	if (basis.size() > BLOCK)
		return test_a();
	else
		return test_b();
	
}

Compilation message

insects.cpp: In function 'int test_a()':
insects.cpp:35:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   35 |   int m = l+r>>1;
      |           ~^~
insects.cpp: In function 'int get_min(int, int, std::vector<int>&)':
insects.cpp:51:3: error: 'debug' was not declared in this scope
   51 |   debug(l, v);
      |   ^~~~~
insects.cpp:54:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   54 |  int m = l+r>>1;
      |          ~^~