# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1101530 | 2024-10-16T09:27:04 Z | ngongocbich | K blocks (IZhO14_blocks) | C++17 | 48 ms | 262144 KB |
#include <bits/stdc++.h> #define int long long #define mask(k) (1<<(k)) using namespace std; int n,k,a[1000001],dp[1000001][101],l[1000001],mx[1001][21]; stack<int> st; int getmn(int l, int r) { int p=__lg(r-l+1); return min(mx[l][p],mx[r-mask(p)+1][p]); } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); freopen("w.inp","r",stdin); freopen("w.out","w",stdout); cin>>n>>k; for (int i=1; i<=n; i++) cin>>a[i],mx[i][0]=0x3f; for (int j=1; mask(j)<=n; j++) for (int i=1; i+mask(j)-1<=n; i++) mx[i][j]=min(mx[i][j-1],mx[i+mask(j-1)][j-1]); for (int i=1; i<=n; i++) { while (!st.empty() && a[st.top()]<=a[i]) st.pop(); if (!st.empty()) l[i]=st.top(); else l[i]=0; st.push(i); } memset(dp,0x3f,sizeof(dp)); dp[0][0]=0; for (int i=1; i<=k; i++) for (int j=1; j<=n; j++) { dp[i][j]=min(dp[i][j],a[j]+getmn(l[j],j-1)); dp[i][j]=min(dp[i][j],dp[i][l[j]]); } cout<<dp[k][n]; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 42 ms | 262144 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 48 ms | 262144 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 42 ms | 262144 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 42 ms | 262144 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |