Submission #1077369

# Submission time Handle Problem Language Result Execution time Memory
1077369 2024-08-27T06:07:31 Z Faisal_Saqib Rarest Insects (IOI22_insects) C++17
10 / 100
42 ms 2596 KB
#include <bits/stdc++.h>
using namespace std;
void move_inside(int i);
void move_outside(int i);
int press_button();
map<set<int>,int> store;
set<int> cur,real_;
void add(int i)
{
	i--;
	cur.insert(i);
}
void rem(int i)
{
	i--;
	if(cur.find(i)!=cur.end())
		cur.erase(i);
}
void khatam()
{
	cur.clear();
}
int ask()
{
	if(store.find(cur)!=store.end())return store[cur];
	for(auto i:cur)
	{
		if(real_.find(i)==real_.end())
		{
			real_.insert(i);
			move_inside(i);
		}
	}
	set<int> rem;
	for(auto j:real_)
	{
		if(cur.find(j)==cur.end())
		{
			rem.insert(j);
			move_outside(j);
		}
	}
	for(auto i:rem)real_.erase(i);
	store[cur]=press_button();
	// cout<<"asking \n";
	// cout<<"For: ";
	// for(auto i:cur)
	// {
	// 	cout<<i<<' ';
	// }
	// cout<<endl;
	// cout<<"Ans: "<<store[cur]<<endl;
	return store[cur];
}
const int M=2e3+10;
int par[M],sz[M];
int get(int x)
{
	if(par[x]==x)return x;
	return par[x]=get(par[x]);
}
void merge(int x,int y)
{
	x=get(x);
	y=get(y);
	par[y]=x;
	sz[x]+=sz[y];
}
int min_cardinality(int n)
{
	for(int i=1;i<=n;i++)
		par[i]=i,sz[i]=1;
	vector<int> heads={1};
	for(int i=2;i<=n;i++)
	{

		int sz=heads.size();
		int s=-1,e=sz;
		while(s+1<e)
		{
			int mid=(s+e)/2;
			khatam();
			for(int j=s+1;j<=mid;j++)
				add(heads[j]);
			add(i);
			int aft=ask();
			if(aft==2)
			{
				e=mid;
			}
			else
			{
				s=mid;
			}
		}
		if(e==sz)
		{
			heads.push_back(i);
		}
		else
		{
			merge(heads[e],i);
		}
	}
	int mi=n+1;
	for(auto i:heads)
		mi=min(mi,sz[i]);
	return mi;
}
# 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 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 2 ms 344 KB Output is correct
7 Correct 26 ms 1332 KB Output is correct
8 Correct 9 ms 856 KB Output is correct
9 Correct 6 ms 600 KB Output is correct
10 Correct 3 ms 344 KB Output is correct
11 Correct 18 ms 944 KB Output is correct
12 Correct 6 ms 344 KB Output is correct
13 Correct 6 ms 600 KB Output is correct
14 Correct 3 ms 456 KB Output is correct
15 Correct 6 ms 344 KB Output is correct
16 Correct 4 ms 480 KB Output is correct
17 Correct 5 ms 600 KB Output is correct
18 Correct 5 ms 508 KB Output is correct
19 Correct 6 ms 600 KB Output is correct
20 Correct 12 ms 856 KB Output is correct
21 Correct 15 ms 1000 KB Output is correct
22 Correct 23 ms 1828 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 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 2 ms 344 KB Output is correct
7 Correct 26 ms 1332 KB Output is correct
8 Correct 9 ms 856 KB Output is correct
9 Correct 6 ms 600 KB Output is correct
10 Correct 3 ms 344 KB Output is correct
11 Correct 18 ms 944 KB Output is correct
12 Correct 6 ms 344 KB Output is correct
13 Correct 6 ms 600 KB Output is correct
14 Correct 3 ms 456 KB Output is correct
15 Correct 6 ms 344 KB Output is correct
16 Correct 4 ms 480 KB Output is correct
17 Correct 5 ms 600 KB Output is correct
18 Correct 5 ms 508 KB Output is correct
19 Correct 6 ms 600 KB Output is correct
20 Correct 12 ms 856 KB Output is correct
21 Correct 15 ms 1000 KB Output is correct
22 Correct 23 ms 1828 KB Output is correct
23 Correct 7 ms 520 KB Output is correct
24 Incorrect 40 ms 2596 KB Too many queries.
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 360 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 8 ms 952 KB Output is correct
8 Incorrect 42 ms 2432 KB Too many queries.
9 Halted 0 ms 0 KB -