#include <bits/stdc++.h>
#include "insects.h"
#define pb push_back
using namespace std;
//#include "../debug.h"
#define debug(x...) void(42)
constexpr static int BLOCK = 1;
int n;
set<int> basis;
bool check(int val)
{
vector<int> ci;
int counter = basis.size();
for (int i = 0; i < n; i++)
{
if (basis.find(i) != basis.end())
continue;
move_inside(i);
counter++;
if (press_button() > val)
{
move_outside(i);
counter--;
}
}
return counter >= val * basis.size();
}
int test_a()
{
int l = -1, r = n+1;
while (r - l > 1)
{
int m = l+r>>1;
if(check(m))
l = m;
else
r = m;
}
return l;
}
vector<int> bs;
set<int> machine;
int get_min(int l, int r, vector<int>& v)
{
if (r - l == 1)
{
debug(l, v);
return v.size()+1;
}
int m = l+r>>1;
for (int i = 0; i < n; i++)
{
if (i >= l && i < m)
{
if (machine.find(bs[i]) != machine.end())
continue;
machine.insert(bs[i]);
move_inside(bs[i]);
}
if (i < l || i >= m)
{
if (machine.find(bs[i]) == machine.end())
continue;
machine.erase(bs[i]);
move_outside(bs[i]);
}
}
vector<int> lv, rv;
for (int i : v)
{
move_inside(i);
if (press_button() > 1)
lv.pb(i);
else
rv.pb(i);
move_outside(i);
}
int lres = get_min(l, m, lv);
int rres = get_min(m, r, rv);
return min(lres, rres);
}
int test_b()
{
for (int i : basis)
{
bs.pb(i);
machine.insert(i);
}
vector<int> v;
for (int i = 0; i < n; i++)
if (basis.find(i) == basis.end())
v.pb(i);
return get_min(0, bs.size(), v);
}
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
basis.insert(i);
}
if (basis.size() > BLOCK)
return test_a();
else
return test_b();
}
Compilation message
insects.cpp: In function 'bool check(int)':
insects.cpp:30:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::set<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | return counter >= val * basis.size();
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
insects.cpp: In function 'int test_a()':
insects.cpp:38:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
38 | int m = l+r>>1;
| ~^~
insects.cpp: In function 'int get_min(int, int, std::vector<int>&)':
insects.cpp:56:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
56 | int m = l+r>>1;
| ~^~
# |
결과 |
실행 시간 |
메모리 |
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 |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
2 ms |
208 KB |
Output is correct |
8 |
Incorrect |
12 ms |
208 KB |
Wrong answer. |
9 |
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 |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
2 ms |
208 KB |
Output is correct |
8 |
Incorrect |
12 ms |
208 KB |
Wrong answer. |
9 |
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 |
208 KB |
Output is correct |
6 |
Partially correct |
1 ms |
208 KB |
Output is partially correct |
7 |
Correct |
17 ms |
280 KB |
Output is correct |
8 |
Correct |
14 ms |
364 KB |
Output is correct |
9 |
Incorrect |
124 ms |
296 KB |
Wrong answer. |
10 |
Halted |
0 ms |
0 KB |
- |