Submission #1101543

#TimeUsernameProblemLanguageResultExecution timeMemory
1101543thanhhoangK blocks (IZhO14_blocks)C++14
100 / 100
277 ms49548 KiB
#include<bits/stdc++.h> using namespace std; const int N=1e5+53; int n,k,a[N],b[102][N],c[N],e[N],f[N][20]; stack<int>d; void build(int oo) { for(int i=0;i<=n;i++) f[i][0]=b[oo][i]; for(int i=1;(1 << i) <= n;i++) for(int j=0;j+(1<<i)-1<=n;j++) f[j][i]=min(f[j][i-1],f[j+(1<<i-1)][i-1]); } int get(int l,int r) { if (l > r) return 1e9; int o=__lg(r-l+1); return min(f[l][o],f[r-(1<<o)+1][o]); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if(fopen("cc.inp","r")) { freopen("cc.inp","r",stdin); freopen("cc.out","w",stdout); } cin>>n>>k; a[0]=1e9; d.push(0); for(int i=1;i<=n;i++) { cin>>a[i]; while(a[d.top()]<=a[i]) d.pop(); c[i]=d.top(); d.push(i); } memset(b,0x3f,sizeof b); b[0][0]=0; for(int i=1;i<=k;i++) { build(i-1); for(int j=1;j<=n;j++) b[i][j]=min(b[i][c[j]],get(c[j],j-1)+a[j]); } cout<<b[k][n]; return 0; }

Compilation message (stderr)

blocks.cpp: In function 'void build(int)':
blocks.cpp:11:44: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   11 |             f[j][i]=min(f[j][i-1],f[j+(1<<i-1)][i-1]);
      |                                           ~^~
blocks.cpp: In function 'int main()':
blocks.cpp:25:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |         freopen("cc.inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~
blocks.cpp:26:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         freopen("cc.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...