#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++)
{
khatam();
for(auto p:heads)add(p);
add(i);
if(ask()==2)
{
int sz=heads.size();
int s=-1,e=sz;
// can be head[s]
// not head[e]
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);
}
}
else
{
heads.push_back(i);
}
}
int mi=n+1;
for(auto i:heads)
mi=min(mi,sz[i]);
return mi;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 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 |
352 KB |
Output is correct |
7 |
Correct |
9 ms |
1228 KB |
Output is correct |
8 |
Correct |
8 ms |
600 KB |
Output is correct |
9 |
Correct |
9 ms |
1104 KB |
Output is correct |
10 |
Correct |
5 ms |
344 KB |
Output is correct |
11 |
Correct |
12 ms |
1308 KB |
Output is correct |
12 |
Correct |
5 ms |
600 KB |
Output is correct |
13 |
Correct |
8 ms |
620 KB |
Output is correct |
14 |
Correct |
5 ms |
620 KB |
Output is correct |
15 |
Correct |
6 ms |
600 KB |
Output is correct |
16 |
Correct |
9 ms |
600 KB |
Output is correct |
17 |
Correct |
7 ms |
516 KB |
Output is correct |
18 |
Correct |
7 ms |
672 KB |
Output is correct |
19 |
Correct |
10 ms |
948 KB |
Output is correct |
20 |
Correct |
19 ms |
1124 KB |
Output is correct |
21 |
Correct |
20 ms |
1440 KB |
Output is correct |
22 |
Correct |
19 ms |
1464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 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 |
352 KB |
Output is correct |
7 |
Correct |
9 ms |
1228 KB |
Output is correct |
8 |
Correct |
8 ms |
600 KB |
Output is correct |
9 |
Correct |
9 ms |
1104 KB |
Output is correct |
10 |
Correct |
5 ms |
344 KB |
Output is correct |
11 |
Correct |
12 ms |
1308 KB |
Output is correct |
12 |
Correct |
5 ms |
600 KB |
Output is correct |
13 |
Correct |
8 ms |
620 KB |
Output is correct |
14 |
Correct |
5 ms |
620 KB |
Output is correct |
15 |
Correct |
6 ms |
600 KB |
Output is correct |
16 |
Correct |
9 ms |
600 KB |
Output is correct |
17 |
Correct |
7 ms |
516 KB |
Output is correct |
18 |
Correct |
7 ms |
672 KB |
Output is correct |
19 |
Correct |
10 ms |
948 KB |
Output is correct |
20 |
Correct |
19 ms |
1124 KB |
Output is correct |
21 |
Correct |
20 ms |
1440 KB |
Output is correct |
22 |
Correct |
19 ms |
1464 KB |
Output is correct |
23 |
Correct |
8 ms |
600 KB |
Output is correct |
24 |
Correct |
312 ms |
23888 KB |
Output is correct |
25 |
Correct |
85 ms |
4052 KB |
Output is correct |
26 |
Correct |
88 ms |
4216 KB |
Output is correct |
27 |
Correct |
11 ms |
600 KB |
Output is correct |
28 |
Incorrect |
89 ms |
6424 KB |
Too many queries. |
29 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 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 |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
11 ms |
600 KB |
Output is correct |
8 |
Execution timed out |
2041 ms |
94940 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |