#include <bits/stdc++.h>
#include "insects.h"
#define pb push_back
using namespace std;
//#define DEBUGGING
#ifdef DEBUGGING
#include "../debug.h"
#else
#define debug(x...) void(42)
#endif
int n;
set<int> basis;
set<int> machine;
bool check(int val)
{
vector<int> ci;
for (int i = 0; i < n; i++)
{
if (machine.find(i) != machine.end())
continue;
move_inside(i);
machine.insert(i);
if (press_button() > val)
{
ci.pop_back();
move_outside(i);
machine.erase(i);
}
}
bool res = machine.size() == val * basis.size();
debug(val, res);
return res;
}
int test_a()
{
int l = 1, r = 1 + (n / basis.size());
debug(l, r);
while (r - l > 1)
{
int m = l+r>>1;
debug(m);
if(check(m))
{
l = m;
}
else
{
for (auto it = machine.begin(); it != machine.end(); it)
if (basis.find(*it) == basis.end())
machine.erase(it++);
else
it++;
r = m;
}
}
debug(l);
return l;
}
vector<int> bs;
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 = l; i < m; i++)
{
if (machine.find(bs[i]) != machine.end())
continue;
machine.insert(bs[i]);
move_inside(bs[i]);
}
for (int i = m; i < r; i++)
{
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()
{
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);
}
for (int i : basis)
{
bs.pb(i);
machine.insert(i);
}
return test_a();
/*
if (basis.size() > BLOCK)
return test_a();
else
return test_b();
*/
}
Compilation message
insects.cpp: In function 'int test_a()':
insects.cpp:46:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
46 | int m = l+r>>1;
| ~^~
insects.cpp:54:57: warning: for increment expression has no effect [-Wunused-value]
54 | for (auto it = machine.begin(); it != machine.end(); it)
| ^~
insects.cpp: In function 'int get_min(int, int, std::vector<int>&)':
insects.cpp:74:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
74 | 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 |
6 ms |
208 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
5 ms |
300 KB |
Output is correct |
9 |
Incorrect |
4 ms |
304 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 |
208 KB |
Output is correct |
6 |
Correct |
6 ms |
208 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
5 ms |
300 KB |
Output is correct |
9 |
Incorrect |
4 ms |
304 KB |
Wrong answer. |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 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 |
0 ms |
208 KB |
Output is correct |
7 |
Correct |
54 ms |
324 KB |
Output is correct |
8 |
Correct |
18 ms |
456 KB |
Output is correct |
9 |
Correct |
37 ms |
284 KB |
Output is correct |
10 |
Partially correct |
61 ms |
336 KB |
Output is partially correct |
11 |
Partially correct |
98 ms |
208 KB |
Output is partially correct |
12 |
Correct |
26 ms |
300 KB |
Output is correct |
13 |
Partially correct |
164 ms |
288 KB |
Output is partially correct |
14 |
Partially correct |
75 ms |
292 KB |
Output is partially correct |
15 |
Incorrect |
79 ms |
312 KB |
Wrong answer. |
16 |
Halted |
0 ms |
0 KB |
- |