제출 #258288

#제출 시각아이디문제언어결과실행 시간메모리
258288karmaK개의 묶음 (IZhO14_blocks)C++14
100 / 100
178 ms3068 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()) cur.ans = min(cur.ans, v.back().ans); f[i & 1][j] = cur.ans; v.pb(cur); } } cout << f[k & 1][n]; }

컴파일 시 표준 에러 (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...