This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <cstring>
#define int long long
using namespace std;
const int INF=1e18;
int dp[20001][51],n,T,s,t[20001],a[51][20001],cur;
string score[51];
int C(int i, int j){
int cnt=0;
for (int k=1;k<=n;k++)
cnt+=(a[k][j]-a[k][i-1]==j-i+1);
return (t[j]-t[i-1])*cnt;
}
int f(int i, int j){
if (j<0)
return INF;
if (!i)
return (j?INF:0);
if (dp[i][j]!=-1)
return dp[i][j];
dp[i][j]=INF;
for (int k=j;k<=i;k++)
dp[i][j]=min(dp[i][j],f(k-1,j-1)+C(k,i));
return dp[i][j];
}
int32_t main(){
ios_base::sync_with_stdio(NULL);cin.tie(nullptr);
cin >> n >> T >> s;
for (int i=1;i<=T;i++){
cin >> t[i];
t[i]+=t[i-1];
}
for (int i=1;i<=n;i++){
cin >> score[i];
for (int j=0;j<T;j++)
a[i][j+1]=a[i][j]+score[i][j]-'0';
}
memset(dp,-1,sizeof(dp));
for (int i=1;i<=s;i++)
cout << f(T,i) << '\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... |