Submission #770662

#TimeUsernameProblemLanguageResultExecution timeMemory
770662Perl32Stove (JOI18_stove)C++14
0 / 100
1 ms320 KiB
/** * author: Perl32 * created: 28.06.2023 20:23:30 **/ #ifdef LOCAL # define _GLIBCXX_DEBUG #endif #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #define ff first #define ss second #define szof(x) (int) x.size() #define all(x) x.begin(), x.end() #ifndef LOCAL # define cerr __get_ce #endif using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll, ll> pll; typedef pair<int, int> pii; typedef complex<double> cmpl; typedef unsigned long long ull; using namespace __gnu_pbds; template<typename K, typename V> using normal_unordered_map = gp_hash_table<K, V>; template<typename T> using normal_queue = priority_queue<T, vector<T>, greater<T>>; template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template<typename K, typename V> using ordered_map = tree<K, V, less<K>, rb_tree_tag, tree_order_statistics_node_update>; template<typename T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } template<typename T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } const int INF = (int) 1e9 + 1e3; const ll INFL = (ll) 1e18 + 1e9; #ifdef LOCAL mt19937 tw(9450189); #else mt19937 tw(chrono::high_resolution_clock::now().time_since_epoch().count()); #endif uniform_int_distribution<ll> ll_distr; ll rnd(ll a, ll b) { return ll_distr(tw) % (b - a + 1) + a; } signed main() { #ifdef LOCAL freopen("inp.txt", "r", stdin); freopen("out.txt", "w", stdout); freopen("err.txt", "w", stderr); auto start_time = clock(); cerr << setprecision(3) << fixed; #endif ios_base::sync_with_stdio(false); cin.tie(nullptr); int n, k; cin >> n >> k; vector<int> a(n + 1); for (int i = 1; i <= n; ++i) { cin >> a[i]; } auto get = [&](ll opt) { vector<pair<ll, int>> dp(n + 1, {INFL, 0}); vector<pair<ll, int>> pref(n + 1); dp[0] = {0, 0}; for (int i = 1; i <= n; ++i) { pref[i] = {dp[i - 1].ff + 1 - a[i] + opt, dp[i - 1].ss}; int id = -1; for (int j = 1; j <= i; ++j) { id = j; dp[i] = min(dp[i], {dp[j - 1].ff + a[i] + 1 - a[j] + opt, dp[j - 1].ss + 1}); } if (i > 1) { pref[i] = min(pref[i], pref[i - 1]); } } return dp[n]; }; ll l = 0, r = INFL; while (l + 1 < r) { ll m = (l + r) >> 1; if (get(m).ss >= k) { l = m; } else { r = m; } } cout << get(r).ff - k * r; #ifdef LOCAL auto end_time = clock(); cerr << "Execution time: " << (end_time - start_time) * (ll) 1e3 / CLOCKS_PER_SEC << " ms\n"; #endif }

Compilation message (stderr)

stove.cpp: In lambda function:
stove.cpp:69:17: warning: variable 'id' set but not used [-Wunused-but-set-variable]
   69 |             int id = -1;
      |                 ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...