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;
#pragma GCC optimize("O2,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("Os")
#define F first
#define S second
#define pb push_back
#define SZ(x) (ll)(x.size())
#define all(x) x.begin(),x.end()
//#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll maxn=50+10, maxm=2e4+10, lg=22, mod=1e9+9, inf=1e18;
ll n,t,s;
ll a[maxm],pre[maxm][maxn],dp[maxn][maxm],mnn[maxn][maxn];
int main(){
ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin>>n>>t>>s;
for(int i=1;i<=t;i++) cin>>a[i], a[i]+=a[i-1];
for(int i=1;i<=n;i++){
string s; cin>>s;
for(int j=1;j<=t;j++) pre[j][i]=(s[j-1]=='0' ? j:pre[j-1][i]);
}
for(int i=1;i<=t;i++) pre[i][n+1]=i, sort(pre[i]+1,pre[i]+n+1);
memset(dp,69,sizeof(dp)), memset(mnn,69,sizeof(mnn));
dp[0][0]=0;
for(int i=1;i<=s;cout<<dp[i++][t]<<endl)for(int j=1;j<=t;j++)for(int k=0;k<=n;k++){
for(int l=pre[j-1][k+1];l<pre[j][k+1];l++) mnn[k][i]=min(mnn[k][i],dp[i-1][l]-a[l]*k);
if(pre[j][k+1]) dp[i][j]=min(dp[i][j],mnn[k][i]+a[j]*k);
}
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... |