Submission #830939

# Submission time Handle Problem Language Result Execution time Memory
830939 2023-08-19T13:21:41 Z caganyanmaz Rarest Insects (IOI22_insects) C++17
99.95 / 100
53 ms 452 KB
#include <bits/stdc++.h>
#include "insects.h"
#define pb push_back
using namespace std;

#ifdef DEBUGGING
#include "../debug.h"
#else
#define debug(x...) void(42)
#endif

constexpr static int BLOCK = 10;

int n;
set<int> basis;
int _prev;
set<int> unav;


int counter = 0;
bool check(int val)
{
	set<int> l, r;
	for (int i = 0; i < n && (_prev + l.size()) < val * basis.size(); i++)
	{
		if (unav.find(i) != unav.end())
			continue;
		move_inside(i);
		counter++;
		if (press_button() > val)
		{
			counter++;
			move_outside(i);
			r.insert(i);
		}
		else
		{
			l.insert(i);
		}
	}
	bool res = ( _prev + l.size() ) == val * basis.size();
	debug(res, l.size(), _prev, val, basis.size());
	if (res)
	{
		for (int i : l)
			unav.insert(i);
		_prev += l.size();
	}
	else
	{
		for (int i : r)
			unav.insert(i);
		for (int i : l)
		{
			move_outside(i);
			counter++;
		}
	}
	return res;
}

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

vector<int> bs;

int min_cardinality(int N)
{
	n = N;
	for (int i = 0; i < n; i++)
	{
		counter++;
		move_inside(i);
		if (press_button() > 1)
		{
			move_outside(i);
			counter++;
		}
		else
		{
			basis.insert(i);
		}
	}	
	for (int i : basis)
	{
		bs.pb(i);
		unav.insert(i);
	}
	_prev = basis.size();
	return test_a();
	
}

Compilation message

insects.cpp: In function 'int test_a()':
insects.cpp:68:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   68 |   int m = l+r>>1;
      |           ~^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 3 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 4 ms 208 KB Output is correct
9 Correct 5 ms 208 KB Output is correct
10 Correct 4 ms 208 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 6 ms 208 KB Output is correct
13 Correct 4 ms 208 KB Output is correct
14 Correct 4 ms 304 KB Output is correct
15 Correct 4 ms 208 KB Output is correct
16 Correct 4 ms 208 KB Output is correct
17 Correct 5 ms 300 KB Output is correct
18 Correct 5 ms 208 KB Output is correct
19 Correct 2 ms 300 KB Output is correct
20 Correct 4 ms 300 KB Output is correct
21 Correct 3 ms 208 KB Output is correct
22 Correct 2 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 3 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 4 ms 208 KB Output is correct
9 Correct 5 ms 208 KB Output is correct
10 Correct 4 ms 208 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 6 ms 208 KB Output is correct
13 Correct 4 ms 208 KB Output is correct
14 Correct 4 ms 304 KB Output is correct
15 Correct 4 ms 208 KB Output is correct
16 Correct 4 ms 208 KB Output is correct
17 Correct 5 ms 300 KB Output is correct
18 Correct 5 ms 208 KB Output is correct
19 Correct 2 ms 300 KB Output is correct
20 Correct 4 ms 300 KB Output is correct
21 Correct 3 ms 208 KB Output is correct
22 Correct 2 ms 208 KB Output is correct
23 Correct 19 ms 300 KB Output is correct
24 Correct 7 ms 328 KB Output is correct
25 Correct 21 ms 300 KB Output is correct
26 Correct 25 ms 320 KB Output is correct
27 Correct 18 ms 328 KB Output is correct
28 Correct 8 ms 320 KB Output is correct
29 Correct 18 ms 300 KB Output is correct
30 Correct 18 ms 292 KB Output is correct
31 Correct 19 ms 288 KB Output is correct
32 Correct 17 ms 336 KB Output is correct
33 Correct 24 ms 328 KB Output is correct
34 Correct 16 ms 288 KB Output is correct
35 Correct 20 ms 288 KB Output is correct
36 Correct 21 ms 328 KB Output is correct
37 Correct 18 ms 328 KB Output is correct
38 Correct 22 ms 328 KB Output is correct
39 Correct 19 ms 304 KB Output is correct
40 Correct 10 ms 308 KB Output is correct
41 Correct 10 ms 316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 35 ms 288 KB Output is correct
8 Correct 14 ms 372 KB Output is correct
9 Correct 40 ms 296 KB Output is correct
10 Correct 46 ms 412 KB Output is correct
11 Correct 46 ms 328 KB Output is correct
12 Correct 27 ms 404 KB Output is correct
13 Correct 41 ms 420 KB Output is correct
14 Correct 49 ms 412 KB Output is correct
15 Correct 40 ms 328 KB Output is correct
16 Correct 41 ms 288 KB Output is correct
17 Correct 31 ms 328 KB Output is correct
18 Correct 33 ms 280 KB Output is correct
19 Correct 42 ms 276 KB Output is correct
20 Correct 37 ms 280 KB Output is correct
21 Correct 42 ms 324 KB Output is correct
22 Correct 51 ms 412 KB Output is correct
23 Correct 42 ms 428 KB Output is correct
24 Correct 38 ms 332 KB Output is correct
25 Correct 28 ms 320 KB Output is correct
26 Correct 13 ms 452 KB Output is correct
27 Correct 42 ms 296 KB Output is correct
28 Correct 14 ms 296 KB Output is correct
29 Correct 53 ms 408 KB Output is correct
30 Correct 38 ms 288 KB Output is correct
31 Correct 47 ms 296 KB Output is correct
32 Correct 51 ms 412 KB Output is correct
33 Correct 36 ms 332 KB Output is correct
34 Correct 36 ms 316 KB Output is correct
35 Partially correct 48 ms 416 KB Output is partially correct
36 Correct 39 ms 424 KB Output is correct
37 Correct 49 ms 296 KB Output is correct
38 Correct 49 ms 300 KB Output is correct
39 Correct 44 ms 312 KB Output is correct
40 Correct 24 ms 300 KB Output is correct
41 Correct 29 ms 424 KB Output is correct
42 Partially correct 40 ms 352 KB Output is partially correct
43 Correct 9 ms 296 KB Output is correct
44 Correct 37 ms 420 KB Output is correct
45 Correct 22 ms 328 KB Output is correct
46 Correct 27 ms 424 KB Output is correct
47 Correct 21 ms 424 KB Output is correct
48 Correct 26 ms 416 KB Output is correct