/**
____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|
**/
#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef long long ll;
const int T_MAX = 20000;
const int N_MAX = 50;
const int S_MAX = 50;
int T, N, S;
int points[T_MAX + 2];
bool solved[N_MAX + 2][T_MAX + 2];
int pref[T_MAX + 2];
int streak[T_MAX + 2][N_MAX + 2];
int minSum[S_MAX + 2][T_MAX + 2];
int SGT[N_MAX + 2][T_MAX + 2];
void build (int SGT[], int node, int l, int r, int arr[]) {
if (l == r) {
SGT[node] = arr[l];
return;
}
int mid = (l + r) / 2;
int lSon = node * 2, rSon = node * 2 + 1;
build(SGT, lSon, l, mid, arr);
build(SGT, rSon, mid + 1, r, arr);
SGT[node] = min(SGT[lSon], SGT[rSon]);
}
void build (int SGT[], int arr[]) {
build(SGT, 1, 0, T, arr);
}
int query (int SGT[], int node, int l, int r, int ql, int qr) {
if (ql <= l && r <= qr) {
return SGT[node];
}
int mid = (l + r) / 2;
int lSon = node * 2, rSon = node * 2 + 1;
int answer = INT_MAX;
if (ql <= mid) {
answer = min(answer, query(SGT, lSon, l, mid, ql, qr));
}
if (mid + 1 <= qr) {
answer = min(answer, query(SGT, rSon, mid + 1, r, ql, qr));
}
return answer;
}
int query (int SGT[], int ql, int qr) {
return query(SGT, 1, 0, T, ql, qr);
}
int arr[T_MAX + 2];
signed main () {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> N >> T >> S;
for (int t = 1; t <= T; t++) {
cin >> points[t];
pref[t] = pref[t - 1] + points[t];
}
for (int i = 1; i <= N; i++) {
string str;
cin >> str;
for (int t = 1; t <= T; t++) {
solved[i][t] = (str[t - 1] == '1');
}
}
for (int t = 1; t <= T; t++) {
for (int i = 1; i <= N; i++) {
streak[t][i] = (solved[i][t] == true ? streak[t - 1][i] + 1 : 0);
}
}
for (int t = 1; t <= T; t++) {
for (int i = 1; i <= N; i++) {
streak[t][i] = t - streak[t][i] + 1;
}
streak[t][0] = 1;
streak[t][N + 1] = T + 1;
sort(streak[t] + 0, streak[t] + N + 1);
}
for (int t = 1; t <= T; t++) {
minSum[0][t] = INT_MAX;
}
for (int s = 1; s <= S; s++) {
for (int k = 0; k <= N; k++) {
for (int t = 0; t <= T; t++) {
if (minSum[s - 1][t] < INT_MAX) {
arr[t] = minSum[s - 1][t] - pref[t] * k;
} else {
arr[t] = INT_MAX;
}
}
build(SGT[k], arr);
}
minSum[s][0] = INT_MAX;
for (int t = 1; t <= T; t++) {
minSum[s][t] = INT_MAX;
for (int k = 0; k <= N; k++) {
int l = streak[t][k], r = min(streak[t][k + 1] - 1, t);
if (l <= r) {
int sum = query(SGT[k], l - 1, r - 1);
if (sum < INT_MAX) {
minSum[s][t] = min(minSum[s][t], sum + pref[t] * k);
}
}
}
}
cout << minSum[s][T] << "\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
58 ms |
1768 KB |
Output is correct |
2 |
Correct |
62 ms |
1840 KB |
Output is correct |
3 |
Correct |
73 ms |
1756 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
351 ms |
5896 KB |
Output is correct |
2 |
Correct |
525 ms |
6924 KB |
Output is correct |
3 |
Correct |
743 ms |
7628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
724 KB |
Output is correct |
3 |
Correct |
58 ms |
1768 KB |
Output is correct |
4 |
Correct |
62 ms |
1840 KB |
Output is correct |
5 |
Correct |
73 ms |
1756 KB |
Output is correct |
6 |
Correct |
351 ms |
5896 KB |
Output is correct |
7 |
Correct |
525 ms |
6924 KB |
Output is correct |
8 |
Correct |
743 ms |
7628 KB |
Output is correct |
9 |
Correct |
1373 ms |
13208 KB |
Output is correct |
10 |
Incorrect |
1766 ms |
16276 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |