Submission #1060077

# Submission time Handle Problem Language Result Execution time Memory
1060077 2024-08-15T10:30:09 Z parsadox2 Rarest Insects (IOI22_insects) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#include "insects.h"

using namespace std;

const int N = 2e3 + 10;
int n;
bool bad[N] , dead[N];

bool check(int mid)
{
	for(int i = 0 ; i < n ; i++)  if(!dead[i])
	{
		bad[i] = false;
		move_inside(i);
		int val = press_button();
		if(val > mid)
		{
			bad[i] = true;
			move_outside(i);
		}
	}
	for(int i = 0 ; i < n ; i++)  if(!bad[i] && !dead[i])
		move_outside(i);
	bool flg = true;
	vector <int> vec;
	for(int i = 0 ; i < n ; i++)  if(bad[i] && !dead[i])
	{
		flg = false;
		move_inside(i);
		int val = press_button();
		if(val > 1)
			move_outside(i);
		else
			vec.push_back(i);
	}
	if(flg)
		return true;
	for(int i = 0 ; i < n ; i++)  if(!bad[i] && !dead[i])
	{
		move_inside(i);
		int val = press_button();
		if(val == 1)
		{
			flg = true;
		}
		else
		{
			bad[i] = true;
		}
		move_outside(i);
	}
	for(auto u : vec)
		move_outside(i);
	if(!flg)
		return false;
	for(int i = 0 ; i < n ; i++)  if(bad[i])
		dead[i] = true;
	return flg;
}

int min_cardinality(int nn)
{
	n = nn;
	int low = 0 , high = n;
	while(high - low > 1)
	{
		int mid = (low + high) >> 1;
		if(check(mid))
			high = mid;
		else
			low = mid;
	}
	return high;
}

Compilation message

insects.cpp: In function 'bool check(int)':
insects.cpp:54:16: error: 'i' was not declared in this scope
   54 |   move_outside(i);
      |                ^
insects.cpp:53:11: warning: unused variable 'u' [-Wunused-variable]
   53 |  for(auto u : vec)
      |           ^