Submission #1078072

#TimeUsernameProblemLanguageResultExecution timeMemory
1078072WjscK blocks (IZhO14_blocks)C++14
100 / 100
195 ms84820 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define pi pair<int, int> #define fi first #define se second #define all(v) v.begin(), v.end() const int N = 1e5 + 5, M = 1e2 + 5; int n, k; int a[N]; int f[N][M]; signed main() { cin.tie(0)->sync_with_stdio(0); if(fopen("task.inp", "r")) { freopen("task.inp", "r", stdin); freopen("task.out", "w", stdout); } memset(f, 120, sizeof f); cin >> n >> k; for(int i = 1; i <= n; ++i) { cin >> a[i]; if(i > 1) f[i][1] = max(f[i - 1][1], a[i]); else f[i][1] = a[i]; } for(int j = 2; j <= k; ++j) { stack<pi> st; for(int i = j; i <= n; ++i) { int c = f[i - 1][j - 1]; while(st.size() && a[st.top().fi] <= a[i]) { c = min(c, st.top().se); st.pop(); } f[i][j] = c + a[i]; if(st.size()) f[i][j] = min(f[i][j], f[st.top().fi][j]); st.push({i, c}); } } cout << f[n][k]; }

Compilation message (stderr)

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