Submission #223585

#TimeUsernameProblemLanguageResultExecution timeMemory
223585MKopchevPopeala (CEOI16_popeala)C++14
100 / 100
1452 ms14816 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[tmax]; 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[1<<16]; void update(int node,int l,int r,int pos,int val) { if(l==r) { tree[node]=val; return; } int av=(l+r)/2; if(pos<=av)update(node*2,l,av,pos,val); else update(node*2+1,av+1,r,pos,val); tree[node]=min(tree[node*2],tree[node*2+1]); } int query(int node,int l,int r,int lq,int rq) { if(l==lq&&r==rq)return tree[node]; int av=(l+r)/2,ret=inf; if(lq<=av)ret=min(ret,query(node*2,l,av,lq,min(av,rq))); if(av<rq)ret=min(ret,query(node*2+1,av+1,r,max(av+1,lq),rq)); return ret; } int moments_mem[nmax][tmax]; int pref_min[tmax]; 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<=tasks;i++) dp[0][i]=inf; for(int sub=1;sub<=want;sub++) { dp[sub][0]=inf; for(int i=1;i<=tasks;i++) { 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=0;w<=n+1;w++) { moments_mem[w][i]=moments[w]; } //cout<<sub<<" "<<i<<" -> "<<dp[sub][i]<<endl; } for(int i=0;i<=tasks;i++)dp[sub][i]=inf; for(int w=0;w<=n;w++) { pref_min[0]=inf; for(int i=1;i<=tasks;i++) { pref_min[i]=min(pref_min[i-1],dp[sub-1][i-1]-w*pref[i-1]); if(sub>i)continue; int lhs=moments_mem[w][i]+1,rhs=moments_mem[w+1][i]; if(lhs>rhs)continue; dp[sub][i]=min(dp[sub][i],pref_min[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:62: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:64: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...