#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
const int N = 20005, D = 55, inf = 2e9;
int n, t, s;
int a[N], mi[D], lt[N][D], dp[N][D];
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n >> t >> s;
for (int i = 1; i <= t; ++i) {
cin >> a[i];
a[i] += a[i - 1];
}
for (int i = 0; i < n; ++i) {
string s; cin >> s;
for (int j = 0; j < t; ++j) {
lt[j + 1][i] = s[j] == '1' ? lt[j][i] : j + 1;
}
}
for (int i = 1; i <= t; ++i) {
lt[i][n] = i;
sort(lt[i], lt[i] + n + 1);
}
fill(dp[0] + 1, dp[0] + t + 1, inf);
for (int i = 1; i <= s; ++i) {
fill(mi, mi + n + 1, inf);
dp[i][0] = inf;
for (int j = 1; j <= t; ++j) {
dp[i][j] = inf;
for (int k = 0; k <= n; ++k) {
for (int p = lt[j - 1][k]; p < lt[j][k]; ++p) {
if (dp[i - 1][p] ^ inf) {
mi[k] = min(mi[k], dp[i - 1][p] - a[p] * k);
}
}
if (mi[k] ^ inf) {
dp[i][j] = min(dp[i][j], mi[k] + a[j] * k);
}
}
}
cout << dp[i][t] << "\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
30 ms |
860 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Incorrect |
6 ms |
2396 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |