Submission #932333

# Submission time Handle Problem Language Result Execution time Memory
932333 2024-02-23T08:21:31 Z alextodoran Chorus (JOI23_chorus) C++17
61 / 100
7000 ms 6408 KB
/**
 _  _   __  _ _ _  _  _ _
 |a  ||t  ||o    d | |o  |
| __    _| | _ | __|  _ |
| __ |/_  | __  /__\ / _\|

**/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

const int N_MAX = 2000000;
const ll INF = LLONG_MAX;
const ld EPS = 1e-9;

int N, K;
int A[N_MAX + 2];

ld dp[N_MAX + 2];
int cnt[N_MAX + 2];

ll cost[N_MAX + 2];

pair <ld, int> f (int j) {
    return make_pair(dp[j] + cost[j + 1], cnt[j]);
}

ll solve (ld pen) {
    fill(cost + 1, cost + N + 1, 0);
    deque <int> rel;
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= i; j++) {
            cost[j] += max(0, (A[i] - i + 1) - j);
        }
        pair <ld, int> mn = f(0);
        for (int j = 1; j <= i - 1; j++) {
            mn = min(mn, f(j));
        }
        tie(dp[i], cnt[i]) = mn;
        dp[i] += pen; cnt[i]++;
    }
    return (ll) round(dp[N] - pen * K);
}

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(2);
    mt19937 rnd(time(0));

    cin >> N >> K;
//    N = 10; K = rnd() % N + 1;
    string S;
    cin >> S;
//    for (int i = 0; i < N * 2; i++) {
//        S += (i < N ? 'A' : 'B');
//    }
//    shuffle(S.begin(), S.end(), rnd);
//    cerr << N << " " << K << "\n";
//    cerr << S << "\n";
    for (int i = 0, j = 0; i < N * 2; i++) {
        if (S[i] == 'A') {
            A[++j] = i + 1;
        }
    }
    ld l = 0, r = LLONG_MAX; int iter = 150;
    while (iter--) {
        ld mid = (l + r) / 2;
        solve(mid);
        if (cnt[N] <= K) {
            r = mid;
        } else {
            l = mid + EPS;
        }
    }
    cout << solve(l) << "\n";

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2508 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2508 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 8 ms 2528 KB Output is correct
18 Correct 57 ms 2524 KB Output is correct
19 Correct 58 ms 2392 KB Output is correct
20 Correct 62 ms 2392 KB Output is correct
21 Correct 64 ms 2560 KB Output is correct
22 Correct 59 ms 2396 KB Output is correct
23 Correct 59 ms 2648 KB Output is correct
24 Correct 61 ms 2392 KB Output is correct
25 Correct 56 ms 2392 KB Output is correct
26 Correct 56 ms 2396 KB Output is correct
27 Correct 56 ms 2396 KB Output is correct
28 Correct 55 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2508 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 8 ms 2528 KB Output is correct
18 Correct 57 ms 2524 KB Output is correct
19 Correct 58 ms 2392 KB Output is correct
20 Correct 62 ms 2392 KB Output is correct
21 Correct 64 ms 2560 KB Output is correct
22 Correct 59 ms 2396 KB Output is correct
23 Correct 59 ms 2648 KB Output is correct
24 Correct 61 ms 2392 KB Output is correct
25 Correct 56 ms 2392 KB Output is correct
26 Correct 56 ms 2396 KB Output is correct
27 Correct 56 ms 2396 KB Output is correct
28 Correct 55 ms 2396 KB Output is correct
29 Correct 5238 ms 2676 KB Output is correct
30 Correct 5374 ms 2680 KB Output is correct
31 Correct 5420 ms 2680 KB Output is correct
32 Correct 6194 ms 2684 KB Output is correct
33 Correct 6001 ms 2684 KB Output is correct
34 Correct 5382 ms 2680 KB Output is correct
35 Correct 5417 ms 2680 KB Output is correct
36 Correct 5529 ms 2684 KB Output is correct
37 Correct 5384 ms 2680 KB Output is correct
38 Correct 5612 ms 2676 KB Output is correct
39 Correct 5503 ms 2680 KB Output is correct
40 Correct 5558 ms 2680 KB Output is correct
41 Correct 5493 ms 2680 KB Output is correct
42 Correct 5784 ms 2684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2508 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 8 ms 2528 KB Output is correct
18 Correct 57 ms 2524 KB Output is correct
19 Correct 58 ms 2392 KB Output is correct
20 Correct 62 ms 2392 KB Output is correct
21 Correct 64 ms 2560 KB Output is correct
22 Correct 59 ms 2396 KB Output is correct
23 Correct 59 ms 2648 KB Output is correct
24 Correct 61 ms 2392 KB Output is correct
25 Correct 56 ms 2392 KB Output is correct
26 Correct 56 ms 2396 KB Output is correct
27 Correct 56 ms 2396 KB Output is correct
28 Correct 55 ms 2396 KB Output is correct
29 Correct 5238 ms 2676 KB Output is correct
30 Correct 5374 ms 2680 KB Output is correct
31 Correct 5420 ms 2680 KB Output is correct
32 Correct 6194 ms 2684 KB Output is correct
33 Correct 6001 ms 2684 KB Output is correct
34 Correct 5382 ms 2680 KB Output is correct
35 Correct 5417 ms 2680 KB Output is correct
36 Correct 5529 ms 2684 KB Output is correct
37 Correct 5384 ms 2680 KB Output is correct
38 Correct 5612 ms 2676 KB Output is correct
39 Correct 5503 ms 2680 KB Output is correct
40 Correct 5558 ms 2680 KB Output is correct
41 Correct 5493 ms 2680 KB Output is correct
42 Correct 5784 ms 2684 KB Output is correct
43 Execution timed out 7102 ms 6408 KB Time limit exceeded
44 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2508 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 8 ms 2528 KB Output is correct
18 Correct 57 ms 2524 KB Output is correct
19 Correct 58 ms 2392 KB Output is correct
20 Correct 62 ms 2392 KB Output is correct
21 Correct 64 ms 2560 KB Output is correct
22 Correct 59 ms 2396 KB Output is correct
23 Correct 59 ms 2648 KB Output is correct
24 Correct 61 ms 2392 KB Output is correct
25 Correct 56 ms 2392 KB Output is correct
26 Correct 56 ms 2396 KB Output is correct
27 Correct 56 ms 2396 KB Output is correct
28 Correct 55 ms 2396 KB Output is correct
29 Correct 5238 ms 2676 KB Output is correct
30 Correct 5374 ms 2680 KB Output is correct
31 Correct 5420 ms 2680 KB Output is correct
32 Correct 6194 ms 2684 KB Output is correct
33 Correct 6001 ms 2684 KB Output is correct
34 Correct 5382 ms 2680 KB Output is correct
35 Correct 5417 ms 2680 KB Output is correct
36 Correct 5529 ms 2684 KB Output is correct
37 Correct 5384 ms 2680 KB Output is correct
38 Correct 5612 ms 2676 KB Output is correct
39 Correct 5503 ms 2680 KB Output is correct
40 Correct 5558 ms 2680 KB Output is correct
41 Correct 5493 ms 2680 KB Output is correct
42 Correct 5784 ms 2684 KB Output is correct
43 Execution timed out 7102 ms 6408 KB Time limit exceeded
44 Halted 0 ms 0 KB -