#include <bits/stdc++.h>
#include "insects.h"
#define pb push_back
using namespace std;
#ifdef DEBUGGING
#include "../debug.h"
#else
#define debug(x...) void(42)
#endif
constexpr static int BLOCK = 10;
int n;
set<int> basis;
set<int> addition;#define DEBUGGING
#ifdef DEBUGGING
#include "../debug.h"
#else
#define debug(x...) void(42)
#endif
constexpr static int BLOCK = 10;
int n;
set<int> basis;
int _prev;
set<int> unav;
int counter = 0;
bool check(int val)
{
set<int> l, r;
for (int i = 0; i < n && (_prev + l.size()) < val * basis.size(); i++)
{
if (unav.find(i) != unav.end())
continue;
move_inside(i);
counter++;
if (press_button() > val)
{
counter++;
move_outside(i);
r.insert(i);
}
else
{
l.insert(i);
}
}
bool res = ( _prev + l.size() ) == val * basis.size();
debug(res, l.size(), _prev, val, basis.size());
if (res)
{
for (int i : l)
unav.insert(i);
_prev += l.size();
}
else
{
for (int i : r)
unav.insert(i);
for (int i : l)
{
move_outside(i);
counter++;
}
}
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
r = m;
}
debug(l);
return l;
}
vector<int> bs;
int min_cardinality(int N)
{
n = N;
for (int i = 0; i < n; i++)
{
counter++;
move_inside(i);
if (press_button() > 1)
{
move_outside(i);
counter++;
}
else
{
basis.insert(i);
}
}
for (int i : basis)
{
bs.pb(i);
unav.insert(i);
}
_prev = basis.size();
return test_a();
}
set<int> machine;
bool check(int val)
{
for (int i = 0; i < n; i++)
{
if (machine.find(i) != machine.end())
continue;
move_inside(i);
addition.insert(i);
if (press_button() > val)
{
move_outside(i);
addition.erase(i);
}
}
bool res = ( machine.size() + addition.size() ) == val * basis.size();
if (res)
for (int i : addition)
machine.insert(i);
else
for (int i : addition)
move_outside(i);
addition.clear();
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
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:17:19: error: stray '#' in program
17 | set<int> addition;#define DEBUGGING
| ^
insects.cpp:17:20: error: 'define' does not name a type
17 | set<int> addition;#define DEBUGGING
| ^~~~~~
insects.cpp:26:5: error: redefinition of 'int n'
26 | int n;
| ^
insects.cpp:15:5: note: 'int n' previously declared here
15 | int n;
| ^
insects.cpp:27:10: error: redefinition of 'std::set<int> basis'
27 | set<int> basis;
| ^~~~~
insects.cpp:16:10: note: 'std::set<int> basis' previously declared here
16 | set<int> basis;
| ^~~~~
insects.cpp: In function 'int test_a()':
insects.cpp:80:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
80 | int m = l+r>>1;
| ~^~
insects.cpp: At global scope:
insects.cpp:122:6: error: redefinition of 'bool check(int)'
122 | bool check(int val)
| ^~~~~
insects.cpp:33:6: note: 'bool check(int)' previously defined here
33 | bool check(int val)
| ^~~~~
insects.cpp:147:5: error: redefinition of 'int test_a()'
147 | int test_a()
| ^~~~~~
insects.cpp:74:5: note: 'int test_a()' previously defined here
74 | int test_a()
| ^~~~~~
insects.cpp: In function 'int test_a()':
insects.cpp:153:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
153 | int m = l+r>>1;
| ~^~
insects.cpp: At global scope:
insects.cpp:163:13: error: redefinition of 'std::vector<int> bs'
163 | vector<int> bs;
| ^~
insects.cpp:91:13: note: 'std::vector<int> bs' previously declared here
91 | vector<int> bs;
| ^~
insects.cpp: In function 'int get_min(int, int, std::vector<int>&)':
insects.cpp:172:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
172 | int m = l+r>>1;
| ~^~
insects.cpp: At global scope:
insects.cpp:212:5: error: redefinition of 'int min_cardinality(int)'
212 | int min_cardinality(int N)
| ^~~~~~~~~~~~~~~
insects.cpp:93:5: note: 'int min_cardinality(int)' previously defined here
93 | int min_cardinality(int N)
| ^~~~~~~~~~~~~~~