Submission #1101530

#TimeUsernameProblemLanguageResultExecution timeMemory
1101530ngongocbichK blocks (IZhO14_blocks)C++17
0 / 100
48 ms262144 KiB
#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 (stderr)

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