#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
int dp[20005][55];
int cost[4005][4005];
int n,t,s;
int val[20005];
bool have[55][20005];
bool bad[55];
int mycost[55];
vector<pii> v;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cin>>n>>t>>s;
for(int i=1;i<=t;i++)
cin>>val[i];
for(int i=1;i<=n;i++)
for(int j=1;j<=t;j++)
{
char c;
cin>>c;
have[i][j]=c-'0';
}
for(int i=1;i<=t;i++)
{
for(int j=1;j<=n;j++)
{
bad[j]=0;
mycost[j]=0;
}
int cur=0;
for(int j=i;j<=t;j++)
{
for(int k=1;k<=n;k++)
if(!bad[k])
{
if(have[k][j])
{
cur+=val[j];
mycost[k]+=val[j];
}
else
{
bad[k]=1;
cur-=mycost[k];
mycost[k]=0;
}
}
cost[i][j]=cur;
}
}
/*dp[0][0]=0;
for(int i=1;i<=s;i++)
dp[0][i]=2e9;
for(int i=1;i<=t;i++)
{
dp[i][0]=2e9;
for(int j=1;j<=s;j++)
{
dp[i][j]=2e9;
for(int k=i-1;k>=0;k--)
dp[i][j]=min(dp[i][j],dp[k][j-1]+cost[k+1][i]);
}
}*/
int suma=cost[1][t];
v.push_back({1,t});
cout<<suma<<'\n';
for(int i=2;i<=s;i++)
{
int ans=2e9;
int poz=0;
for(pii a:v)
{
int st=a.first;
int dr=a.second;
for(int j=st;j<dr;j++)
{
int val=suma-cost[st][dr]+cost[st][j]+cost[j+1][dr];
if(val<ans)
{
ans=val;
poz=j;
}
}
}
vector<pii> x;
for(pii a:v)
{
if(a.first<=poz&&a.second>=poz)
{
x.push_back({a.first,poz});
x.push_back({poz+1,a.second});
}
else
x.push_back(a);
}
v=x;
suma=ans;
cout<<ans<<'\n';
}
/*for(int i=1;i<=s;i++)
cout<<dp[t][i]<<'\n';*/
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
324 KB |
Output is correct |
2 |
Incorrect |
1 ms |
596 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
3032 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
91 ms |
19016 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
324 KB |
Output is correct |
2 |
Incorrect |
1 ms |
596 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |