Submission #627911

#TimeUsernameProblemLanguageResultExecution timeMemory
627911tutisRarest Insects (IOI22_insects)C++17
25 / 100
475 ms63008 KiB
#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; int lo, hi; 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; } lo = 1; hi = N / c; double bias = 3.2; pair<double, int>dp[hi + 1][hi + 1]; for (int sz = 1; sz <= hi; sz++) { int m = 0; for (int l = 1; l + sz - 1 <= hi; l++) { int r = l + sz - 1; if (sz == 1) dp[l][r] = {0, 0}; else { int cost = N - lo * c; int m0 = l + 1; int m1 = r; m = max(m, m0); m = min(m, m1); for (int delt = -15; delt <= 15; delt++) { while (m + delt >= m0 && m + delt <= m1) { if (max(dp[l][m + delt - 1].first, dp[m + delt][r].first) < max(dp[l][m - 1].first, dp[m][r].first)) m += delt; else break; } } dp[l][r].first = max(dp[l][m - 1].first, dp[m][r].first); dp[l][r].first += cost; dp[l][r].second = m; } } } 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:43:12: warning: unused variable 'bias' [-Wunused-variable]
   43 |     double bias = 3.2;
      |            ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...