Submission #1078249

# Submission time Handle Problem Language Result Execution time Memory
1078249 2024-08-27T14:31:02 Z Faisal_Saqib Rarest Insects (IOI22_insects) C++17
99.95 / 100
762 ms 21624 KB
#include <bits/stdc++.h>
using namespace std;
void move_inside(int i);
void move_outside(int i);
int press_button();
set<int> machine,rem,real_;
int sm=0;
void add(int x)
{
	if(machine.find(x)==machine.end())
	{
		// move_inside(x);
		machine.insert(x);
	}
}
void remp(int x)
{
	if(machine.find(x)!=machine.end())
	{
		// move_outside(x);
		machine.erase(x);
	}
}
map<vector<int>,int> store;
int ask()
{
	for(auto&i:real_)
	{
		if(machine.find(i)==machine.end())
		{
			move_outside(i);
		}	
	}
	for(auto&i:machine)
	{
		if(real_.find(i)==real_.end())
		{
			move_inside(i);
		}
	}
	real_=machine;
	vector<int> cur(begin(machine),end(machine));
	if(store.find(cur)==store.end())
		store[cur]=press_button();
	// cout<<"Query for: ";
	// for(auto j:cur)
	// {
	// 	cout<<j<<' ';
	// }
	// cout<<" ans: "<<store[cur]<<endl;
	return store[cur];
}
int min_cardinality(int n)
{
	add(0);
	for(int i=1;i<n;i++)
	{
		add(i);
		if(ask()>1)
		{
			rem.insert(i);
			remp(i);
		}
	}
	int sz=machine.size();
	int s=1;
	int e=(n/sz)+1;
	while(s+1<e)
	{
		int mid=(s+e)/2;
		vector<int> cur;
		// cout<<endl;
		// cout<<"for "<<mid<<endl;
		// cout<<"\nMachine: ";
		// for(auto j:machine)
		// {
		// 	cout<<j<<' ';
		// }
		// cout<<endl;
		for(auto&i:rem)
		{
			// cout<<"Add and query "<<i<<endl;
			add(i);
			if(ask()>mid)
			{
				remp(i);
			}
			else
			{
				cur.push_back(i);
				if(machine.size()==(sz*mid))
					break;
			}
		}
		if(machine.size()==((sz*mid)))
		{
			s=mid;
			for(auto&i:cur)
				rem.erase(i);
		}
		else{
			e=mid;
			rem.clear();
			for(auto&i:cur)
			{
				rem.insert(i);
				remp(i);
			}
		}
	}
	return s;
}

Compilation message

insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:91:22: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   91 |     if(machine.size()==(sz*mid))
      |        ~~~~~~~~~~~~~~^~~~~~~~~~
insects.cpp:95:20: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   95 |   if(machine.size()==((sz*mid)))
      |      ~~~~~~~~~~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 5 ms 344 KB Output is correct
7 Correct 4 ms 344 KB Output is correct
8 Correct 5 ms 472 KB Output is correct
9 Correct 8 ms 600 KB Output is correct
10 Correct 5 ms 600 KB Output is correct
11 Correct 3 ms 600 KB Output is correct
12 Correct 5 ms 556 KB Output is correct
13 Correct 5 ms 344 KB Output is correct
14 Correct 9 ms 1148 KB Output is correct
15 Correct 6 ms 596 KB Output is correct
16 Correct 9 ms 560 KB Output is correct
17 Correct 7 ms 524 KB Output is correct
18 Correct 8 ms 856 KB Output is correct
19 Correct 8 ms 556 KB Output is correct
20 Correct 4 ms 600 KB Output is correct
21 Correct 4 ms 472 KB Output is correct
22 Correct 3 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 5 ms 344 KB Output is correct
7 Correct 4 ms 344 KB Output is correct
8 Correct 5 ms 472 KB Output is correct
9 Correct 8 ms 600 KB Output is correct
10 Correct 5 ms 600 KB Output is correct
11 Correct 3 ms 600 KB Output is correct
12 Correct 5 ms 556 KB Output is correct
13 Correct 5 ms 344 KB Output is correct
14 Correct 9 ms 1148 KB Output is correct
15 Correct 6 ms 596 KB Output is correct
16 Correct 9 ms 560 KB Output is correct
17 Correct 7 ms 524 KB Output is correct
18 Correct 8 ms 856 KB Output is correct
19 Correct 8 ms 556 KB Output is correct
20 Correct 4 ms 600 KB Output is correct
21 Correct 4 ms 472 KB Output is correct
22 Correct 3 ms 600 KB Output is correct
23 Correct 56 ms 2996 KB Output is correct
24 Correct 46 ms 2828 KB Output is correct
25 Correct 94 ms 3984 KB Output is correct
26 Correct 118 ms 4268 KB Output is correct
27 Correct 42 ms 1620 KB Output is correct
28 Correct 30 ms 1348 KB Output is correct
29 Correct 66 ms 2692 KB Output is correct
30 Correct 80 ms 2740 KB Output is correct
31 Correct 106 ms 3588 KB Output is correct
32 Correct 84 ms 3920 KB Output is correct
33 Correct 147 ms 4960 KB Output is correct
34 Correct 110 ms 4120 KB Output is correct
35 Correct 95 ms 4172 KB Output is correct
36 Correct 114 ms 3788 KB Output is correct
37 Correct 126 ms 4208 KB Output is correct
38 Correct 101 ms 3408 KB Output is correct
39 Correct 97 ms 3096 KB Output is correct
40 Correct 89 ms 3176 KB Output is correct
41 Correct 48 ms 1872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 318 ms 10608 KB Output is correct
8 Correct 330 ms 10812 KB Output is correct
9 Correct 645 ms 15588 KB Output is correct
10 Correct 494 ms 15156 KB Output is correct
11 Correct 136 ms 5192 KB Output is correct
12 Correct 237 ms 8880 KB Output is correct
13 Correct 201 ms 6904 KB Output is correct
14 Correct 270 ms 8948 KB Output is correct
15 Correct 465 ms 13096 KB Output is correct
16 Correct 448 ms 13904 KB Output is correct
17 Correct 482 ms 13876 KB Output is correct
18 Correct 545 ms 15540 KB Output is correct
19 Correct 544 ms 15292 KB Output is correct
20 Correct 542 ms 15344 KB Output is correct
21 Correct 475 ms 15268 KB Output is correct
22 Correct 399 ms 12740 KB Output is correct
23 Correct 268 ms 9708 KB Output is correct
24 Correct 352 ms 12828 KB Output is correct
25 Correct 306 ms 11344 KB Output is correct
26 Correct 166 ms 7040 KB Output is correct
27 Correct 644 ms 19660 KB Output is correct
28 Correct 273 ms 11180 KB Output is correct
29 Correct 760 ms 20832 KB Output is correct
30 Correct 745 ms 20632 KB Output is correct
31 Correct 525 ms 14892 KB Output is correct
32 Correct 526 ms 15952 KB Output is correct
33 Correct 270 ms 9808 KB Output is correct
34 Correct 235 ms 9300 KB Output is correct
35 Partially correct 727 ms 20984 KB Output is partially correct
36 Correct 591 ms 16228 KB Output is correct
37 Correct 500 ms 14812 KB Output is correct
38 Correct 556 ms 14540 KB Output is correct
39 Correct 662 ms 19340 KB Output is correct
40 Correct 279 ms 10320 KB Output is correct
41 Correct 562 ms 16892 KB Output is correct
42 Partially correct 762 ms 21624 KB Output is partially correct
43 Correct 20 ms 728 KB Output is correct
44 Correct 69 ms 2932 KB Output is correct
45 Correct 321 ms 10700 KB Output is correct
46 Correct 128 ms 6944 KB Output is correct
47 Correct 266 ms 10744 KB Output is correct
48 Correct 182 ms 8740 KB Output is correct