#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int n,t,s;cin>>n>>t>>s;
vector<string>r(n+1);
int p[t+1] = {0};
for(int i = 1;i<=t;i++){cin>>p[i];p[i]+=p[i-1];}
for(int i = 1;i<=n;i++)cin>>r[i];
int a[t+1][n+1];
memset(a,0,sizeof a);
for(int i = 1;i<=t;i++){
for(int j = 1;j<=n;j++){
a[i][j] = (r[j][i-1]=='0'?i:a[i-1][j]);
}
}
for(int i = 1;i<=t;i++){
a[i][0] = i;
sort(a[i],a[i]+n+1);
}
int dp[s+1][t+1];
for(int i = 0;i<=s;i++)for(int j = 0;j<=t;j++)dp[i][j] = 1e9;
dp[0][0] = 0;
for(int i = 1;i<=s;i++){
int b[n+1];
for(int j = 0;j<=n;j++)b[j]=1e9;
for(int j = 1;j<=t;j++){
for(int k = 0;k<=n;k++){
for(int l=a[j-1][k]; l<a[j][k]; ++l)
b[k]=min(dp[i-1][l]-p[l]*k,b[k]);
dp[i][j]=min(b[k]+p[j]*k,dp[i][j]);
}
}
cout<<dp[i][t]<<"\n";
}
}
//
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
468 KB |
Output is correct |
2 |
Correct |
6 ms |
468 KB |
Output is correct |
3 |
Correct |
6 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
1236 KB |
Output is correct |
2 |
Correct |
49 ms |
1620 KB |
Output is correct |
3 |
Correct |
52 ms |
2132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
7 ms |
468 KB |
Output is correct |
4 |
Correct |
6 ms |
468 KB |
Output is correct |
5 |
Correct |
6 ms |
468 KB |
Output is correct |
6 |
Correct |
36 ms |
1236 KB |
Output is correct |
7 |
Correct |
49 ms |
1620 KB |
Output is correct |
8 |
Correct |
52 ms |
2132 KB |
Output is correct |
9 |
Correct |
66 ms |
3320 KB |
Output is correct |
10 |
Correct |
116 ms |
4244 KB |
Output is correct |
11 |
Correct |
168 ms |
9392 KB |
Output is correct |
12 |
Correct |
190 ms |
10672 KB |
Output is correct |
13 |
Correct |
259 ms |
10704 KB |
Output is correct |
14 |
Correct |
255 ms |
10688 KB |
Output is correct |
15 |
Correct |
256 ms |
10680 KB |
Output is correct |