#include <bits/stdc++.h>
using namespace std;
typedef long long int64;
const int maxt = 2e4 + 2;
const int maxn = 51;
int dp[maxt][maxn]; // dp[i][j] -> minimum score divinding first i tests in j subtasks
// int prec[maxt][maxt]; // prec[i][j] -> left of the segment containing suffix of j ones considering first i elements
int prec[maxn][maxt]; // prec[i][j] -> pos of last 0 considering first i elements of the j-th ciuvak
int a[maxt];
int sum[maxn];
int col [maxt];
string s[maxn];
int main() {
int n,t,mk;
cin >> n >> t >> mk;
for (int i = 0; i < maxt; i++) for (int j = 0; j < maxn; j++) dp[i][j] = 2e9;
memset(prec, 0, sizeof(prec));
for (int i = 1; i <= t; i++){
cin >> a[i];
dp[i][1] = 0;
sum[i] = sum[i-1] + a[i];
}
for (int i = 1; i <= n; i++){
cin >> s[i];
int prf = 0;
for (int j = 1; j <= t; j++){
col[j]+=(s[i][j-1] - '0');
prf+= (s[i][j-1] - '0');
dp[j][1]+=(prf == 1) * sum[j];
if (s[i][j-1] == '1') prec[i][j] = prec[i][j-1];
else prec[i][j] = j;
}
}
for (int i = 1; i <= t; i++){
prec[0][i] = i;
// sort(prec[i], prec[i] + n + 1);
}
for (int k = 2; k <= mk; k++){
for (int i = 1; i <= t; i++){
for (int c = 0; c <= n; c++){
int sf = 2e9;
for (int j = prec[c][i - 1]; j < prec[c][i]; j++){
sf = min(sf, dp[j][k - 1] - c * sum[j]);
}
dp[i][k] = min(dp[i][k], sf + c * sum[i]);
}
}
}
for (int i = 1; i <= mk; i++){
for (int j = 1; j <= t; j++){
cout << dp[j][i] << " ";
}
cout << "\n";
}
// for (int i = 1; i <= mk; i++){
// cout << dp[t][i] << "\n";
// }
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
8276 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
11 ms |
8368 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
38 ms |
9544 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
8276 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |