#include <bits/stdc++.h>
using namespace std;
const int inf = 2e9 + 5;
int pref[20'005];
bool ac[55][20'005];
int dp[55][20'005];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int ppl, cases, grp; cin >> ppl >> cases >> grp;
pref[0] = 0;
for (int i = 1; i <= cases; i++) {
cin >> pref[i];
pref[i] += pref[i - 1];
}
for (int i = 1; i <= ppl; i++){
string str; cin >> str;
for (int j = 1; j <= cases; j++) ac[i][j] = (str[j - 1] == '1');
}
for (int i = 0; i <= grp; i++)
for (int j = 0; j <= cases; j++)
dp[i][j] = inf;
dp[0][0] = 0;
for (int i = 1; i <= grp; i++){
int best[55], last[55], fc[20'005];
memset(best, 0, sizeof(best));
memset(last, 0, sizeof(last));
for (int j = 0; j <= cases; j++) fc[j] = ppl;
for (int j = 1; j <= cases; j++){
if (dp[i - 1][best[ppl]] + (pref[j] - pref[best[ppl]]) * fc[best[ppl] + 1] > dp[i - 1][j - 1] + (pref[j] - pref[j - 1]) * ppl) best[ppl] = j - 1;
for (int p = 1; p <= ppl; p++){
if (ac[p][j]) continue;
for (int k = last[p] + 1; k <= j; k++) best[fc[k]] = 0;
for (int k = last[p] + 1; k <= j; k++){
fc[k]--;
if (dp[i - 1][best[fc[k]]] + (pref[j] - pref[best[fc[k]]]) * fc[k] > dp[i - 1][k - 1] + (pref[j] - pref[k - 1]) * fc[k]) best[fc[k]] = k - 1;
}
last[p] = j;
}
if (j < i) continue;
for (int p = 0; p <= ppl; p++) dp[i][j] = min(dp[i][j], dp[i - 1][best[p]] + (pref[j] - pref[best[p]]) * fc[best[p] + 1]);
}
cout << dp[i][cases] << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
936 KB |
Output is correct |
2 |
Correct |
14 ms |
928 KB |
Output is correct |
3 |
Correct |
15 ms |
852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
61 ms |
1344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
16 ms |
936 KB |
Output is correct |
4 |
Correct |
14 ms |
928 KB |
Output is correct |
5 |
Correct |
15 ms |
852 KB |
Output is correct |
6 |
Incorrect |
61 ms |
1344 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |