Submission #258284

#TimeUsernameProblemLanguageResultExecution timeMemory
258284karmaK blocks (IZhO14_blocks)C++14
0 / 100
10 ms1152 KiB
#include <bits/stdc++.h> #define pb emplace_back #define ll long long #define fi first #define se second #define mp make_pair //#define int int64_t using namespace std; const int N = int(1e6) + 7; const int inf = 1e9 + 1; typedef pair<ll, ll> pii; struct TNode { int x, y, ans; TNode() {x = y = ans = inf;} TNode(int x, int y): x(x), y(y) { ans = x + y; } void minimize(const TNode& o) { x = min(x, o.x); ans = min(ans, x + y); } } cur; int f[2][N], n, k, a[N]; vector<TNode> v; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); #define Task "test" if(fopen(Task".inp", "r")) { freopen(Task".inp", "r", stdin); freopen(Task".out", "w", stdout); } cin >> n >> k; for(int i = 1; i <= n; ++i) { cin >> a[i]; f[1][i] = max(f[1][i - 1], a[i]); } for(int i = 2; i <= k; ++i) { v.clear(); for(int j = i; j <= n; ++j) { cur = TNode(f[(i & 1) ^ 1][j - 1], a[j]); while(v.size() && v.back().y <= cur.y) { cur.minimize(v.back()); v.pop_back(); } if(v.size()) f[i & 1][j] = min(v.back().ans, cur.ans); else f[i & 1][j] = cur.ans; v.pb(cur); } } cout << f[k & 1][n]; }

Compilation message (stderr)

blocks.cpp: In function 'int32_t main()':
blocks.cpp:34:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen(Task".inp", "r", stdin);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
blocks.cpp:35:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         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...