This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*input
2 3 3
4 3 5
101
110
0
1
2
-1
1
2
-1
-1
1
*/
#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){
int p=0;
REP1(i,m){
while(p<i){
int ans=0;
REP(a,n){
if(cnt[a][i]-cnt[a][p]!=(i-p)) ++ans;
}
if(ans<j) break;
++p;
}
turn[i][j]=p-1;
//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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |