Submission #223572

#TimeUsernameProblemLanguageResultExecution timeMemory
223572MKopchevPopeala (CEOI16_popeala)C++14
17 / 100
2073 ms4932 KiB
#include<bits/stdc++.h> using namespace std; const int nmax=50+5,tmax=20000+5,inf=2e9+42; int n,tasks,want; int points[tmax]; bool solved[nmax][tmax]; int prv_bad[nmax][tmax]; int pref[nmax]; int ask(int l,int r) { int ret=0,sum=pref[r]-pref[l-1]; for(int i=1;i<=n;i++) if(prv_bad[i][r]<l)ret=ret+sum; return ret; } int dp[nmax][tmax]; int moments[nmax]; int tree[nmax][1<<16]; void update(int which,int node,int l,int r,int pos,int val) { if(l==r) { tree[which][node]=val; return; } int av=(l+r)/2; if(pos<=av)update(which,node*2,l,av,pos,val); else update(which,node*2+1,av+1,r,pos,val); tree[which][node]=min(tree[which][node*2],tree[which][node*2+1]); } int query(int which,int node,int l,int r,int lq,int rq) { if(l==lq&&r==rq)return tree[which][node]; int av=(l+r)/2,ret=inf; if(lq<=av)ret=min(ret,query(which,node*2,l,av,lq,min(av,rq))); if(av<rq)ret=min(ret,query(which,node*2+1,av+1,r,max(av+1,lq),rq)); return ret; } int main() { scanf("%i%i%i",&n,&tasks,&want); for(int i=1;i<=tasks;i++)scanf("%i",&points[i]); for(int i=1;i<=tasks;i++)pref[i]=pref[i-1]+points[i]; for(int i=1;i<=n;i++) for(int j=1;j<=tasks;j++) { char in=getchar(); while(in!='0'&&in!='1')in=getchar(); if(in=='1')solved[i][j]=1; } for(int i=1;i<=n;i++) { for(int j=1;j<=tasks;j++) if(solved[i][j]==0)prv_bad[i][j]=j; else prv_bad[i][j]=prv_bad[i][j-1]; } /* for(int i=1;i<=n;i++) for(int j=1;j<=tasks;j++) cout<<i<<" "<<j<<" -> "<<nxt_bad[i][j]<<endl; */ for(int i=1;i<=tasks;i++) dp[0][i]=inf; for(int sub=1;sub<=want;sub++) { dp[sub][0]=inf; for(int w=0;w<=n;w++) for(int cur=1;cur<=tasks;cur++) update(w,1,1,tasks,cur,dp[sub-1][cur-1]-w*pref[cur-1]); for(int i=1;i<=tasks;i++) { dp[sub][i]=inf; if(sub>i)continue; for(int j=1;j<=n;j++)moments[j]=prv_bad[j][i]; sort(moments+1,moments+n+1); moments[n+1]=i; for(int w=n;w>=0;w--) { int lhs=moments[w]+1,rhs=moments[w+1]; if(lhs>rhs)continue; dp[sub][i]=min(dp[sub][i],query(w,1,1,tasks,lhs,rhs)+w*pref[i]); } //cout<<sub<<" "<<i<<" -> "<<dp[sub][i]<<endl; } printf("%i\n",dp[sub][tasks]); } return 0; }

Compilation message (stderr)

popeala.cpp: In function 'int main()':
popeala.cpp:58:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%i%i%i",&n,&tasks,&want);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
popeala.cpp:60:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=1;i<=tasks;i++)scanf("%i",&points[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...