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 <bits/stdc++.h>
using namespace std;
//#define int long long
#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
ll mod=1000000007;
int inf=1000000007;
ll infl=100000000007;
const int N=20007,M=52;
ll DP[N][M];
ll a[N];
char is[M][N];
int last[M];
vector<ll>P[N][M];
int ile[N];
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int m,n,s;
cin>>m>>n>>s;
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;i<=n;i++) a[i]+=a[i-1];
for(int i=1;i<=m;i++) for(int j=1;j<=n;j++) cin>>is[i][j];
for(int i=1;i<=s;i++) DP[0][i]=infl;
for(int i=1;i<=s;i++)
{
P[0][i].resize(m+1);
for(int l=0;l<=m;l++) P[0][i][l]=infl;
}
P[0][0].resize(m+1,0);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(is[j][i]=='0')
{
ile[last[j]]--;
last[j]=i;
ile[j]++;
}
}
vector<int>V;
for(int j=1;j<=m;j++) if(last[j]>0) V.pb(last[j]);
sort(all(V),greater<int>());
DP[i][0]=infl;
for(int j=1;j<=s;j++)
{
DP[i][j]=infl;
if(j>i) continue;
for(int l=0;l<sz(V);l++)
{
DP[i][j]=min(DP[i][j],P[V[l]-1][j-1][m-l-1]+(ll)(m-l-1)*a[i]);
}
DP[i][j]=min(DP[i][j],P[i-1][j-1][m]+(ll)m*a[i]);
}
for(int j=0;j<=s;j++)
{
P[i][j].resize(m+1);
for(int l=0;l<=m;l++)
{
P[i][j][l]=min(P[i-1][j][l],DP[i][j]-(ll)l*a[i]);
}
}
if(ile[i]==0)
{
for(int j=0;j<=s;j++)
{
P[i-1][j].resize(0);
}
}
}
for(int i=1;i<=s;i++) cout<<DP[n][i]<<endl;
return 0;
}
# | 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... |