#include <bits/stdc++.h>
using namespace std;
void move_inside(int i);
void move_outside(int i);
int press_button();
int min_cardinality(int n)
{
set<int> machine,rem;
int sm=1;
machine.insert(0);
move_inside(0);
for(int i=1;i<n;i++)
{
move_inside(i);
if(press_button()==1)
{
sm++;
machine.insert(i);
}
else
{
rem.insert(i);
move_outside(i);
}
}
int sz=sm;
int s=1;
int e=(n/sz)+1;
while(s+1<e)
{
int mid=(s+e)/2;
vector<int> cur;
for(auto i:rem)
{
move_inside(i);
if(press_button()>mid)
{
move_outside(i);
}
else
{
sm++;
cur.push_back(i);
machine.insert(i);
if(sm==(sz*mid))
break;
}
}
if(sm==((sz*mid)))
{
s=mid;
// We can make values in amachin so keep
for(auto i:cur)
rem.erase(i);
}
else{
e=mid;
sm=0;
for(auto i:cur)
{
rem.insert(i);
machine.erase(i);
move_outside(i);
}
}
}
return s;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
2 ms |
344 KB |
Output is correct |
7 |
Correct |
2 ms |
344 KB |
Output is correct |
8 |
Correct |
3 ms |
344 KB |
Output is correct |
9 |
Incorrect |
4 ms |
344 KB |
Wrong answer. |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
2 ms |
344 KB |
Output is correct |
7 |
Correct |
2 ms |
344 KB |
Output is correct |
8 |
Correct |
3 ms |
344 KB |
Output is correct |
9 |
Incorrect |
4 ms |
344 KB |
Wrong answer. |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 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 |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
27 ms |
344 KB |
Output is correct |
8 |
Correct |
6 ms |
492 KB |
Output is correct |
9 |
Correct |
36 ms |
600 KB |
Output is correct |
10 |
Partially correct |
39 ms |
344 KB |
Output is partially correct |
11 |
Partially correct |
157 ms |
1104 KB |
Output is partially correct |
12 |
Correct |
24 ms |
600 KB |
Output is correct |
13 |
Incorrect |
116 ms |
720 KB |
Wrong answer. |
14 |
Halted |
0 ms |
0 KB |
- |