제출 #1357290

#제출 시각아이디문제언어결과실행 시간메모리
1357290MuhammadSaram조교 (CEOI16_popeala)C++20
0 / 100
2093 ms3132 KiB
#include <bits/stdc++.h>

using namespace std;

#define int long long

const int N = 20001, M = 50, inf = 2e9;

signed main()
{
	int n,m,s;
	cin>>m>>n>>s;
	int a[n], b[m][n], pre[n+1]={};
	for (int i=0;i<n;i++)
		cin>>a[i], pre[i+1]=pre[i]+a[i];
	for (int i=0;i<m;i++)
	{
		string s;
		cin>>s;
		for (int j=0;j<n;j++)
			b[i][j]=s[j]-'0' 	;
	}
	int dp[n+1][s+1]={}, prem[n+1][s+1];
	for (int i=0;i<=n;i++) 
		for (int j=0;j<=s;j++) dp[i][j]=prem[i][j]=inf;
	dp[0][0]=prem[0][0]=0;
	for (int x=1;x<=s;x++)
	{
		int ls[m]={};
		vector<int> se={0};
		for (int i=0;i<m;i++) ls[i]=-1;
		for (int i=0;i<n;i++)
		{
			for (int j=0;j<m;j++)
				if (!b[j][i])
					ls[j]=i, se.push_back(ls[j]);
			int op=se.size();
			for (int o=op-1;o>=max(0ll,op-n);o--)
			{
				int su=0, mn=i;
				for (int j=0;j<m;j++) su+=(pre[i+1]-pre[se[o]])*(se[o]>ls[j]);
				dp[i+1][x]=min(dp[i+1][x],su+dp[se[o]][x-1]);
				if (se[o]==i) continue;
				su=0;
				for (int j=0;j<m;j++) su+=(pre[i+1]-pre[se[o]+1])*(se[o]+1>ls[j]), mn=min(mn,ls[j]);
				dp[i+1][x]=min(dp[i+1][x],su+dp[se[o]][x-1]);
				if (~mn)
					dp[i+1][x]=min(dp[i+1][x],prem[mn][x-1]);
			}
			prem[i+1][x]=min(prem[i][x],dp[i+1][x]);
		}
		cout<<dp[n][x]<<endl;
	}

	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...