#include "insects.h"
#include<bits/stdc++.h>
#define MX 2023
using namespace std;
int n,m,l,r,num,sav,p[MX],pp[MX];
vector<int>d;
int check(int x)
{
for(int i=0;i<n;++i){
if(p[i]||pp[i])continue;
move_inside(i);
if(press_button()>x)move_outside(i);
else{
p[i]=1;
d.push_back(i);
num++;
}
}
return num;
}
int min_cardinality(int N) {
n=N;
for(int i=0;i<n;++i){
move_inside(i);
if(press_button()>1)move_outside(i);
else p[i]=1,num++;
}
m=num;
l=1;
r=n/m;
sav=-1;
while(l<r){
int mid=l+r+1>>1;
if(l+r>=100)mid++;
d.clear();
if(sav!=-1){
d.push_back(sav);
sav=-1;
}
if(check(mid)==mid*m)l=mid;
else{
r=mid-1;
for(int i=0;i<n;++i)
if(!p[i])pp[i]=1;
for(int i=1;i<d.size();++i){
p[d[i]]=0;
move_outside(d[i]);
num--;
}
sav=d[0];
}
}
return l;
}
Compilation message
insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:33:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
33 | int mid=l+r+1>>1;
| ~~~^~
insects.cpp:45:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | for(int i=1;i<d.size();++i){
| ~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
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 |
Execution timed out |
3068 ms |
344 KB |
Time limit exceeded |
7 |
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 |
Execution timed out |
3068 ms |
344 KB |
Time limit exceeded |
7 |
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 |
340 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 |
Execution timed out |
3054 ms |
676 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |