#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];
}
int min_cardinality(int n)
{
vector<int> heads={1};
add(1);
for(int i=2;i<=n;i++)
{
add(i);
if(ask()==1)
heads.push_back(i);
else
rem(i);
}
int sz=heads.size();
int s=1;
int e=n+1;
while(s+1<e)
{
int mid=(s+e)/2;
khatam();
int sm=0;
for(int i=1;i<=mid;i++)
add(i),sm++;
for(int j=mid+1;j<=n;j++)
{
add(j);
if(ask()>mid)
{
rem(j);
}
else{
sm++;
}
}
if(sm==((sz*mid)))
{
s=mid;
}
else{
e=mid;
}
}
return s;
}
# |
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 |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
8 ms |
1624 KB |
Output is correct |
7 |
Correct |
22 ms |
1368 KB |
Output is correct |
8 |
Correct |
23 ms |
2068 KB |
Output is correct |
9 |
Correct |
37 ms |
3708 KB |
Output is correct |
10 |
Correct |
15 ms |
1880 KB |
Output is correct |
11 |
Correct |
34 ms |
5072 KB |
Output is correct |
12 |
Correct |
28 ms |
2980 KB |
Output is correct |
13 |
Correct |
28 ms |
3472 KB |
Output is correct |
14 |
Correct |
33 ms |
3920 KB |
Output is correct |
15 |
Correct |
38 ms |
4288 KB |
Output is correct |
16 |
Correct |
56 ms |
5484 KB |
Output is correct |
17 |
Correct |
30 ms |
3888 KB |
Output is correct |
18 |
Correct |
31 ms |
3616 KB |
Output is correct |
19 |
Correct |
36 ms |
4744 KB |
Output is correct |
20 |
Correct |
37 ms |
3512 KB |
Output is correct |
21 |
Correct |
35 ms |
2920 KB |
Output is correct |
22 |
Correct |
27 ms |
2900 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 |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
8 ms |
1624 KB |
Output is correct |
7 |
Correct |
22 ms |
1368 KB |
Output is correct |
8 |
Correct |
23 ms |
2068 KB |
Output is correct |
9 |
Correct |
37 ms |
3708 KB |
Output is correct |
10 |
Correct |
15 ms |
1880 KB |
Output is correct |
11 |
Correct |
34 ms |
5072 KB |
Output is correct |
12 |
Correct |
28 ms |
2980 KB |
Output is correct |
13 |
Correct |
28 ms |
3472 KB |
Output is correct |
14 |
Correct |
33 ms |
3920 KB |
Output is correct |
15 |
Correct |
38 ms |
4288 KB |
Output is correct |
16 |
Correct |
56 ms |
5484 KB |
Output is correct |
17 |
Correct |
30 ms |
3888 KB |
Output is correct |
18 |
Correct |
31 ms |
3616 KB |
Output is correct |
19 |
Correct |
36 ms |
4744 KB |
Output is correct |
20 |
Correct |
37 ms |
3512 KB |
Output is correct |
21 |
Correct |
35 ms |
2920 KB |
Output is correct |
22 |
Correct |
27 ms |
2900 KB |
Output is correct |
23 |
Correct |
253 ms |
31664 KB |
Output is correct |
24 |
Correct |
1336 ms |
24076 KB |
Output is correct |
25 |
Correct |
876 ms |
26608 KB |
Output is correct |
26 |
Correct |
1587 ms |
118864 KB |
Output is correct |
27 |
Correct |
258 ms |
33160 KB |
Output is correct |
28 |
Correct |
1291 ms |
139988 KB |
Output is correct |
29 |
Correct |
634 ms |
57576 KB |
Output is correct |
30 |
Correct |
795 ms |
61116 KB |
Output is correct |
31 |
Correct |
1546 ms |
89596 KB |
Output is correct |
32 |
Correct |
1553 ms |
101276 KB |
Output is correct |
33 |
Correct |
1639 ms |
109664 KB |
Output is correct |
34 |
Correct |
1394 ms |
81036 KB |
Output is correct |
35 |
Correct |
1635 ms |
105292 KB |
Output is correct |
36 |
Correct |
1518 ms |
105276 KB |
Output is correct |
37 |
Correct |
1364 ms |
110420 KB |
Output is correct |
38 |
Correct |
1202 ms |
86208 KB |
Output is correct |
39 |
Correct |
1045 ms |
77540 KB |
Output is correct |
40 |
Correct |
1153 ms |
72816 KB |
Output is correct |
41 |
Correct |
1249 ms |
76416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1154 ms |
125488 KB |
Output is correct |
8 |
Execution timed out |
3021 ms |
94680 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |