답안 #931996

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
931996 2024-02-22T18:10:58 Z alextodoran Chorus (JOI23_chorus) C++17
40 / 100
7000 ms 2676 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 = 200;
    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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2392 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 2396 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 0 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2392 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 2396 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 0 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 11 ms 2396 KB Output is correct
18 Correct 77 ms 2512 KB Output is correct
19 Correct 83 ms 2528 KB Output is correct
20 Correct 84 ms 2392 KB Output is correct
21 Correct 96 ms 2528 KB Output is correct
22 Correct 78 ms 2520 KB Output is correct
23 Correct 72 ms 2392 KB Output is correct
24 Correct 82 ms 2524 KB Output is correct
25 Correct 84 ms 2400 KB Output is correct
26 Correct 75 ms 2396 KB Output is correct
27 Correct 75 ms 2396 KB Output is correct
28 Correct 82 ms 2524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2392 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 2396 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 0 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 11 ms 2396 KB Output is correct
18 Correct 77 ms 2512 KB Output is correct
19 Correct 83 ms 2528 KB Output is correct
20 Correct 84 ms 2392 KB Output is correct
21 Correct 96 ms 2528 KB Output is correct
22 Correct 78 ms 2520 KB Output is correct
23 Correct 72 ms 2392 KB Output is correct
24 Correct 82 ms 2524 KB Output is correct
25 Correct 84 ms 2400 KB Output is correct
26 Correct 75 ms 2396 KB Output is correct
27 Correct 75 ms 2396 KB Output is correct
28 Correct 82 ms 2524 KB Output is correct
29 Correct 6892 ms 2676 KB Output is correct
30 Execution timed out 7027 ms 2652 KB Time limit exceeded
31 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2392 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 2396 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 0 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 11 ms 2396 KB Output is correct
18 Correct 77 ms 2512 KB Output is correct
19 Correct 83 ms 2528 KB Output is correct
20 Correct 84 ms 2392 KB Output is correct
21 Correct 96 ms 2528 KB Output is correct
22 Correct 78 ms 2520 KB Output is correct
23 Correct 72 ms 2392 KB Output is correct
24 Correct 82 ms 2524 KB Output is correct
25 Correct 84 ms 2400 KB Output is correct
26 Correct 75 ms 2396 KB Output is correct
27 Correct 75 ms 2396 KB Output is correct
28 Correct 82 ms 2524 KB Output is correct
29 Correct 6892 ms 2676 KB Output is correct
30 Execution timed out 7027 ms 2652 KB Time limit exceeded
31 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2392 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 2396 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 0 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 11 ms 2396 KB Output is correct
18 Correct 77 ms 2512 KB Output is correct
19 Correct 83 ms 2528 KB Output is correct
20 Correct 84 ms 2392 KB Output is correct
21 Correct 96 ms 2528 KB Output is correct
22 Correct 78 ms 2520 KB Output is correct
23 Correct 72 ms 2392 KB Output is correct
24 Correct 82 ms 2524 KB Output is correct
25 Correct 84 ms 2400 KB Output is correct
26 Correct 75 ms 2396 KB Output is correct
27 Correct 75 ms 2396 KB Output is correct
28 Correct 82 ms 2524 KB Output is correct
29 Correct 6892 ms 2676 KB Output is correct
30 Execution timed out 7027 ms 2652 KB Time limit exceeded
31 Halted 0 ms 0 KB -