This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "insects.h"
#include <bits/stdc++.h>
using namespace std;
int min_cardinality(vector<int> x)
{
int N = x.size();
int add2 = 0;
int add1 = 0;
vector<int>y;
auto cnt = [&](int c)->int
{
vector<int>v;
y = {};
int k = 0;
for (int i : x)
{
v.push_back(i);
move_inside(i);
k = press_button();
if (k + add1 == c + 1)
{
v.pop_back();
move_outside(i);
y.push_back(i);
}
}
int r = v.size();
for (int i : v)
move_outside(i);
return add2 + r;
};
int c = cnt(1);
if (c * 2 > N)
return 1;
{
x = y;
add2 = c;
add1 = 1;
}
double bias = 3.2;
int mx = N / c;
vector<vector<pair<double, int>>>dp(mx + 1, vector<pair<double, int>>(mx + 1, {0.0, 0}));
for (int sz = 2; sz <= mx; sz++)
{
for (int l = 1; l + sz - 1 <= mx; l++)
{
int r = l + sz - 1;
int m0 = l + 1;
int m1 = r;
int m = round((l * bias + r * 1.0) / (bias + 1));
auto f = [&](int x)
{
x = max(x, l + 1);
x = min(x, r);
return max(dp[l][x - 1].first, dp[x][r].first);
};
if (sz <= 50)
for (int x = l + 1; x <= r; x++)
{
if (f(x) <= f(m))
m = x;
}
else
for (int x = dp[l][r - 1].second - 5; x <= dp[l + 1][r].second + 5; x++)
{
if (f(x) <= f(m))
m = x;
}
m = max(m, l + 1);
m = min(m, r);
dp[l][r].first = f(m) + N - l * c;
dp[l][r].second = m;
}
}
int lo = 1;
int hi = N / c;
while (lo < hi)
{
int m = dp[lo][hi].second;
m = max(m, lo + 1);
m = min(m, hi);
int k = cnt(m);
if (k == m * c)
{
lo = m;
x = y;
add2 = m * c;
add1 = m;
}
else
hi = m - 1;
}
return lo;
}
int min_cardinality(int N) {
vector<int>v;
for (int i = 0; i < N; i++)
v.push_back(i);
return min_cardinality(v);
}
Compilation message (stderr)
insects.cpp: In function 'int min_cardinality(std::vector<int>)':
insects.cpp:48:17: warning: unused variable 'm0' [-Wunused-variable]
48 | int m0 = l + 1;
| ^~
insects.cpp:49:17: warning: unused variable 'm1' [-Wunused-variable]
49 | int m1 = r;
| ^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |