#include "insects.h"
#include <bits/stdc++.h>
using namespace std;
int min_cardinality(int N){
vector<int> v;
int now = 0;
int dif = 0;
auto add = [&](int x){
v.push_back(x);
move_inside(x);
now = press_button();
};
auto del = [&](){
move_outside(v.back());
v.pop_back();
now = press_button();
};
auto del2 = [&](){
move_outside(v.back());
v.pop_back();
now--;
};
add(0);
dif = 1;
for(int i = 1;i<N;i++){
add(i);
if(now == 2){
del2();
}
else dif++;
}
int l = 1,r = N/dif;
while(l < r){
int m = (l + r + 1)/2;
int tmp = now;
press_button();
assert(now == tmp);
if(now < m){
for(int i = 0;i<N;i++){
if(find(v.begin(),v.end(),i) == v.end()){
add(i);
if(now > m)
del2();
}
}
}
else{
vector<int> tmp;
while(now > m){
tmp.push_back(v.back());
del();
}
for(int i = 0;i<N;i++){
if(find(tmp.begin(),tmp.end(),i) == tmp.end() && find(v.begin(),v.end(),i) == v.end()){
add(i);
if(now > m)
del2();
}
}
}
if(v.size() == m * dif){
l = m;
}
else r = m -1;
}
return l;
}
Compilation message
insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:62:15: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
62 | if(v.size() == m * dif){
| ~~~~~~~~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
5 ms |
300 KB |
Output is correct |
7 |
Correct |
2 ms |
208 KB |
Output is correct |
8 |
Correct |
5 ms |
296 KB |
Output is correct |
9 |
Incorrect |
6 ms |
208 KB |
Wrong answer. |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
5 ms |
300 KB |
Output is correct |
7 |
Correct |
2 ms |
208 KB |
Output is correct |
8 |
Correct |
5 ms |
296 KB |
Output is correct |
9 |
Incorrect |
6 ms |
208 KB |
Wrong answer. |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
280 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
49 ms |
292 KB |
Output is correct |
8 |
Correct |
15 ms |
208 KB |
Output is correct |
9 |
Correct |
56 ms |
288 KB |
Output is correct |
10 |
Partially correct |
69 ms |
280 KB |
Output is partially correct |
11 |
Partially correct |
158 ms |
208 KB |
Output is partially correct |
12 |
Correct |
25 ms |
296 KB |
Output is correct |
13 |
Incorrect |
110 ms |
208 KB |
Wrong answer. |
14 |
Halted |
0 ms |
0 KB |
- |