Submission #1245256

#TimeUsernameProblemLanguageResultExecution timeMemory
1245256duyanhloveavK blocks (IZhO14_blocks)C++20
100 / 100
116 ms40876 KiB
#include <bits/stdc++.h> using namespace std; #define MASK(i) (1LL << (i)) #define BIT(x, i) (((x) >> (i)) & 1LL) using ll = long long; const int mxn = 9 + 1e6; const int inf = 0x3f3f3f3f; const ll lnf = 0x3f3f3f3f3f3f3f3f; void _27augain(void) { int n, k; cin >> n >> k; vector<int> a(n + 1); vector<vector<int>> dp(k + 1, vector<int>(n + 1, inf)); for (int i = 1, m = 0; i <= n; ++i) { cin >> a[i]; dp[1][i] = m = max(m, a[i]); } for (int i = 2; i <= k; ++i) { deque<array<int, 2>> q; for (int j = 1; j <= n; ++j) { int v = dp[i - 1][j - 1]; while (!q.empty() && q.back()[0] < a[j]) { v = min(v, q.back()[1]); q.pop_back(); } if (q.empty() || v + a[j] < q.back()[0] + q.back()[1]) { q.push_back({a[j], v}); } dp[i][j] = j >= i ? q.back()[0] + q.back()[1] : inf; } } cout << dp[k][n] << "\n"; } int32_t main(void) { #define task "27augain" cin.tie(0)->sync_with_stdio(0); for (string iext : {"in", "inp"}) { if (fopen((task "." + iext).c_str(), "r")) { freopen((task "." + iext).c_str(), "r", stdin); freopen(task ".out", "w", stdout); } } int testcase = 1; // cin >> testcase; while (testcase--) { _27augain(); } return 0; }

Compilation message (stderr)

blocks.cpp: In function 'int32_t main()':
blocks.cpp:44:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |       freopen((task "." + iext).c_str(), "r", stdin);
      |       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
blocks.cpp:45:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |       freopen(task ".out", "w", stdout);
      |       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...