Submission #1078688

#TimeUsernameProblemLanguageResultExecution timeMemory
1078688Tony_TungK blocks (IZhO14_blocks)C++14
100 / 100
195 ms84396 KiB
#include <bits/stdc++.h> #define task "blocks" #define int long long using namespace std; const int N = 1e5 + 5, K = 1e2 + 5, INF = 1e18; int a[N], dp[N][K], n, k; stack<int> st; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); if (fopen(task".in", "r")) { freopen(task".in", "r", stdin); freopen(task".out", "w", stdout); } cin >> n >> k; for (int i = 0; i <= n; i++) for (int j = 0; j <= k; j++) dp[i][j] = INF; for (int i = 1; i <= n; i++) { cin >> a[i]; dp[i][1] = (i == 1 ? a[i] : max(a[i], dp[i-1][1])); } for (int j = 2; j <= k; j++) { while (st.size()) st.pop(); for (int i = 1; i <= n; i++) { while (st.size() && a[i] >= a[st.top()]) { dp[i][j] = min(dp[i][j], min(dp[st.top()][j-1] + a[i], dp[st.top()][j] - a[st.top()] + a[i])); st.pop(); } if (st.size()) dp[i][j] = min(dp[i][j], min(dp[st.top()][j-1] + a[i], dp[st.top()][j])); st.push(i); } } cout << dp[n][k]; return 0; }

Compilation message (stderr)

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