Submission #49062

#TimeUsernameProblemLanguageResultExecution timeMemory
49062NamnamseoPopeala (CEOI16_popeala)C++17
26 / 100
2089 ms38428 KiB
#include <bits/stdc++.h> using namespace std; #define sz(v) ((int)((v).size())) #define all(v) (v).begin(), (v).end() #define pb push_back #define coord_comp(v) sort(all(v)), v.erase(unique(all(v)), v.end()) #define v_index(v, x) (lower_bound(all(v),x)-(v).begin()) typedef pair<int,int> pp; typedef long long ll; void read(int& x){ scanf("%d",&x); } void read(ll& x){ scanf("%lld",&x); } template<typename T1,typename T2> void read(pair<T1,T2>& p){ read(p.first); read(p.second); } template<typename T,typename... Args> void read(T&a,Args&...b){ read(a); read(b...); } char res[55][20010]; int T, N, S; ll inf=(1ll<<60); ll dp[55][20010]; int point[20010]; int pps[20010]; int sp[55]; struct TREE { static const int M = 32768; ll tree[M*2]; void init(int I,int row){ for(int i=0; i<=T; ++i){ if(dp[I][i]==inf) tree[M+i]=inf; else tree[M+i]=dp[I][i]-row*pps[i]; } for(int i=T+1; i<M; ++i) tree[M+i]=inf; for(int i=M-1; 1<=i; --i){ tree[i]=min(tree[i*2], tree[i*2+1]); } } void init(){ for(int i=0; i<2*M; ++i) tree[i]=inf; } TREE(){ init(); } void upd(int pos,ll val){ pos += M; while(pos){ tree[pos]=min(tree[pos], val); pos /= 2; } } ll range(int l,int r){ ll ret=inf; l+=M; r+=M; while(l<=r){ if(l%2==1) ret=min(ret, tree[l++]); if(r%2==0) ret=min(ret, tree[r--]); l/=2; r/=2; } return ret; } } tr[52]; set<pp> tv; int main(){ //N=S=50; T=20000; read(N, T, S); for(int i=1; i<=T; ++i){ scanf("%d", point+i); pps[i]=pps[i-1]+point[i]; } for(int i=1; i<=N; ++i){ scanf("%s",res[i]+1); } for(int i=1; i<=T; ++i) dp[0][i]=inf; for(int i=0; i<=N; ++i){ tr[i].upd(0, 0); } for(int i=1; i<=S; ++i){ for(int j=0; j<i; ++j) dp[i][j]=inf; for(int k=1; k<=N; ++k) sp[k]=0; tv.clear(); for(int j=i; j<=T; ++j){ for(int k=1; k<=N; ++k){ if(res[k][j] == '0'){ tv.erase({-sp[k], k}); sp[k]=0; } else { if(sp[k]==0){ sp[k]=j; tv.insert({-sp[k], k}); } } } dp[i][j]=inf; int last=j; auto ai=tv.begin(); int cnt=sz(tv); for(;ai!=tv.end();){ auto bi=ai; int delta=0; for(; bi!=tv.end() && ai->first == bi->first; ++bi) ++delta; int t=-ai->first-1; //printf("%d,%d / cnt %d t %d last %d\n", i,j,cnt,t,last); ll tmp = cnt*pps[j] + tr[cnt].range(t, last-1); //printf("tmp %d\n", tmp); dp[i][j] = min(dp[i][j], tmp); last=t; ai=bi; cnt -= delta; } if(0 <= last-1){ //printf("zero %d\n", tr[0].range(0, last-1)); dp[i][j] = min(dp[i][j], tr[0].range(0, last-1)); } //fprintf(F, "%d ",dp[i][j]); } for(int k=0; k<=N; ++k){ tr[k].init(i, k); } //fputc(10, F); printf("%lld\n", dp[i][T]); } /*fputs("hi", F); fclose(F); setbuf(stdout, 0); puts("NOW EASY"); sysetm("./popeala_easy"); sysetm("diff popeala_easy.out popeala.out"); */ return 0; }

Compilation message (stderr)

popeala.cpp: In function 'void read(int&)':
popeala.cpp:10:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 void read(int& x){ scanf("%d",&x); }
                    ~~~~~^~~~~~~~~
popeala.cpp: In function 'void read(ll&)':
popeala.cpp:11:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 void read(ll& x){ scanf("%lld",&x); }
                   ~~~~~^~~~~~~~~~~
popeala.cpp: In function 'int main()':
popeala.cpp:76:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", point+i);
   ~~~~~^~~~~~~~~~~~~~~
popeala.cpp:81:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s",res[i]+1);
   ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...