This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |