Submission #529951

#TimeUsernameProblemLanguageResultExecution timeMemory
529951tht2005K개의 묶음 (IZhO14_blocks)C++17
100 / 100
99 ms2928 KiB
#include <bits/stdc++.h> using namespace std; const int N = 100005; const int INF = 0x3f3f3f3f; int n, kk, a[N], L[N], f[N], g[N], h[N]; int main() { scanf("%d %d", &n, &kk); for(int i = 1; i <= n; ++i) { scanf("%d", a + i); int k = i - 1; while(k > 0 && a[i] >= a[k]) k = L[k]; L[i] = k; } f[0] = 0; for(int i = 1; i <= n; ++i) f[i] = max(f[i - 1], a[i]); for(int i = 2; i <= kk; ++i) { for(int j = 0; j <= n; ++j) { g[j] = f[j]; f[j] = INF; } h[i - 1] = INF; for(int j = i; j <= n; ++j) { h[j] = g[j - 1]; for(int k = j - 1; k > L[j]; k = L[k]) h[j] = min(h[j], h[k]); f[j] = min(f[L[j]], h[j] + a[j]); } } printf("%d", f[n]); return 0; }

Compilation message (stderr)

blocks.cpp: In function 'int main()':
blocks.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |     scanf("%d %d", &n, &kk);
      |     ~~~~~^~~~~~~~~~~~~~~~~~
blocks.cpp:12:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |         scanf("%d", a + i);
      |         ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...