Submission #1078680

#TimeUsernameProblemLanguageResultExecution timeMemory
1078680Tony_TungK blocks (IZhO14_blocks)C++14
53 / 100
883 ms4668 KiB
#include <bits/stdc++.h> #define task "blocks" using namespace std; const int N = 1e5 + 5, K = 1e2 + 5, INF = 2e9; int a[N], dp[N][K], n, k; stack<int> st; int 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 <= n; 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 'int main()':
blocks.cpp:15:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |         freopen(task".in", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
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".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...