#include <bits/stdc++.h>
using namespace std;
const int tmax = 2e4;
const int nmax = 50;
const int oo = INT_MAX;
int n,t,s;
int p[tmax + 5];
int sp[tmax + 5];
char sc[nmax + 5][tmax + 5];
int l[nmax + 5];
int dp[tmax + 5][nmax + 5];
int get_min(int nr, int k, int st, int dr)
{
if(st > dr)
{
return oo;
}
int rez = oo;
for(int i=st; i<=dr; i++)
{
if(dp[i - 1][k - 1] == oo)
{
continue;
}
rez = min(rez, dp[i - 1][k - 1] - nr * sp[i - 1]);
}
return rez;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
#ifdef home
freopen("nr.in","r",stdin);
freopen("nr.out","w",stdout);
#endif // home
cin>>n>>t>>s;
for(int i=1; i<=t; i++)
{
cin>>p[i];
sp[i] = sp[i - 1] + p[i];
}
for(int i=1; i<=n; i++)
{
for(int j=1; j<=t; j++)
{
cin>>sc[i][j];
}
}
for(int i=0; i<=t; i++)
{
for(int k=0; k<=s; k++)
{
dp[i][k] = oo;
}
}
dp[0][0] = 0;
for(int k=1; k<=s; k++)
{
for(int j=1;j<=n;j++)
{
l[j] = 0;
}
for(int i=1; i<=t; i++)
{
vector<int> vl;
for(int j=1; j<=n; j++)
{
if(sc[j][i] == '0')
{
l[j] = i;
}
vl.push_back(l[j]);
}
if(i < k)
{
continue;
}
sort(vl.begin(),vl.end());
vl.push_back(i);
int last = 0;
for(int nr=0; nr<=n; nr++)
{
int val = get_min(nr, k, last + 1, vl[nr]);
if(val != oo)
{
val = val + nr * sp[i];
}
dp[i][k] = min(dp[i][k], val);
last = vl[nr];
}
}
}
for(int k=1; k<=s; k++)
{
cout<<dp[t][k]<<'\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
604 KB |
Output is correct |
2 |
Correct |
33 ms |
604 KB |
Output is correct |
3 |
Correct |
38 ms |
784 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
279 ms |
2988 KB |
Output is correct |
2 |
Correct |
452 ms |
2904 KB |
Output is correct |
3 |
Correct |
718 ms |
2908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
39 ms |
604 KB |
Output is correct |
4 |
Correct |
33 ms |
604 KB |
Output is correct |
5 |
Correct |
38 ms |
784 KB |
Output is correct |
6 |
Correct |
279 ms |
2988 KB |
Output is correct |
7 |
Correct |
452 ms |
2904 KB |
Output is correct |
8 |
Correct |
718 ms |
2908 KB |
Output is correct |
9 |
Correct |
1615 ms |
3248 KB |
Output is correct |
10 |
Execution timed out |
2054 ms |
3164 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |