Submission #536862

#TimeUsernameProblemLanguageResultExecution timeMemory
536862zaneyuPopeala (CEOI16_popeala)C++14
100 / 100
1363 ms11740 KiB
/*input 2 3 3 4 3 5 101 110 */ #include<bits/stdc++.h> using namespace std; #define REP(i,n) for(int i=0;i<n;i++) #define MNTO(x,y) x=min(x,y) #define REP1(i,n) for(int i=1;i<=n;i++) #define ll long long #define ld long double #define sz(x) (int)x.size() #define pb push_back const int maxn=2e4+5; ll dp[maxn],ndp[maxn]; bool ok[maxn]; string s[maxn]; int cnt[55][maxn]; int turn[maxn][55]; ll mn[55]; int p[55]; int pref[maxn]; int main(){ ios::sync_with_stdio(false),cin.tie(0); int n,m,S; cin>>n>>m>>S; REP1(i,m) cin>>pref[i],pref[i]+=pref[i-1]; REP(i,n){ cin>>s[i]; s[i]="0"+s[i]; REP1(j,m){ char c=s[i][j]; cnt[i][j]=cnt[i][j-1]+(c-'0'); } } REP(j,n+1){ REP1(i,m){ int l=0,r=i-1; while(l<r){ int mid=(l+r+1)/2; int ans=0; REP(a,n){ if(cnt[a][i]-cnt[a][mid]!=(i-mid)) ++ans; } if(ans>=j) l=mid; else r=mid-1; } //last point to have >=j ppl not satisfy turn[i][j]=l; int ans=0; REP(a,n){ if(cnt[a][i]-cnt[a][l]!=(i-l)) ++ans; } if(ans<j) turn[i][j]=-1; //assert(turn[i][j]>=turn[i-1][j]); //cout<<turn[i][j]<<'\n'; } } REP(i,m+1) dp[i]=INT_MAX; dp[0]=0; REP1(asd,S){ REP(i,n+1) mn[i]=INT_MAX,p[i]=0; REP1(i,m){ ndp[i]=INT_MAX; REP(j,n+1){ while(p[j]<=turn[i][j]) MNTO(mn[j],dp[p[j]]-(n-j)*pref[p[j]]),p[j]++; MNTO(ndp[i],mn[j]+(n-j)*pref[i]); } //cout<<ndp[i]<<' '; } REP1(j,m) dp[j]=ndp[j]; dp[0]=INT_MAX; cout<<dp[m]<<'\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...