답안 #931755

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
931755 2024-02-22T10:29:25 Z alextodoran Chorus (JOI23_chorus) C++17
40 / 100
279 ms 101800 KB
/**
 _  _   __  _ _ _  _  _ _
 |a  ||t  ||o    d | |o  |
| __    _| | _ | __|  _ |
| __ |/_  | __  /__\ / _\|

**/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N_MAX = 5000;
const int INF = INT_MAX / 2;

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

int dp[N_MAX + 2][N_MAX + 2];
int cost[N_MAX + 2];
int best[N_MAX + 2];

deque <int> rel[N_MAX + 2];

int f (int j, int k) {
    return dp[j][k] + cost[j + 1];
}

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> N >> K;
    string S;
    cin >> S;
    for (int i = 0, j = 0; i < N * 2; i++) {
        if (S[i] == 'A') {
            A[++j] = i + 1;
        }
    }
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= i; j++) {
            cost[j] += max(0, (A[i] - i) - (j - 1));
        }
        dp[i][0] = INF;
        for (int k = 1; k <= K; k++) {
            while (rel[k - 1].empty() == false && f(i - 1, k - 1) <= f(rel[k - 1].back(), k - 1)) {
                rel[k - 1].pop_back();
            }
            rel[k - 1].push_back(i - 1);
            while ((int) rel[k - 1].size() >= 2 && f(rel[k - 1][0], k - 1) >= f(rel[k - 1][1], k - 1)) {
                rel[k - 1].pop_front();
            }
            if (rel[k - 1].empty() == true) {
                dp[i][k] = INF;
            } else {
                dp[i][k] = f(rel[k - 1].front(), k - 1);
            }
        }
    }
    cout << dp[N][K] << "\n";

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5468 KB Output is correct
2 Correct 2 ms 5468 KB Output is correct
3 Correct 2 ms 5468 KB Output is correct
4 Correct 2 ms 5468 KB Output is correct
5 Correct 2 ms 5468 KB Output is correct
6 Correct 2 ms 5468 KB Output is correct
7 Correct 2 ms 5464 KB Output is correct
8 Correct 2 ms 5468 KB Output is correct
9 Correct 2 ms 5468 KB Output is correct
10 Correct 3 ms 5724 KB Output is correct
11 Correct 2 ms 5468 KB Output is correct
12 Correct 2 ms 5572 KB Output is correct
13 Correct 2 ms 5468 KB Output is correct
14 Correct 2 ms 5468 KB Output is correct
15 Correct 2 ms 5468 KB Output is correct
16 Correct 2 ms 5468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5468 KB Output is correct
2 Correct 2 ms 5468 KB Output is correct
3 Correct 2 ms 5468 KB Output is correct
4 Correct 2 ms 5468 KB Output is correct
5 Correct 2 ms 5468 KB Output is correct
6 Correct 2 ms 5468 KB Output is correct
7 Correct 2 ms 5464 KB Output is correct
8 Correct 2 ms 5468 KB Output is correct
9 Correct 2 ms 5468 KB Output is correct
10 Correct 3 ms 5724 KB Output is correct
11 Correct 2 ms 5468 KB Output is correct
12 Correct 2 ms 5572 KB Output is correct
13 Correct 2 ms 5468 KB Output is correct
14 Correct 2 ms 5468 KB Output is correct
15 Correct 2 ms 5468 KB Output is correct
16 Correct 2 ms 5468 KB Output is correct
17 Correct 2 ms 7512 KB Output is correct
18 Correct 4 ms 13912 KB Output is correct
19 Correct 4 ms 13660 KB Output is correct
20 Correct 3 ms 13660 KB Output is correct
21 Correct 3 ms 13660 KB Output is correct
22 Correct 5 ms 13852 KB Output is correct
23 Correct 5 ms 13656 KB Output is correct
24 Correct 4 ms 13812 KB Output is correct
25 Correct 5 ms 13660 KB Output is correct
26 Correct 5 ms 13656 KB Output is correct
27 Correct 4 ms 13660 KB Output is correct
28 Correct 4 ms 13660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5468 KB Output is correct
2 Correct 2 ms 5468 KB Output is correct
3 Correct 2 ms 5468 KB Output is correct
4 Correct 2 ms 5468 KB Output is correct
5 Correct 2 ms 5468 KB Output is correct
6 Correct 2 ms 5468 KB Output is correct
7 Correct 2 ms 5464 KB Output is correct
8 Correct 2 ms 5468 KB Output is correct
9 Correct 2 ms 5468 KB Output is correct
10 Correct 3 ms 5724 KB Output is correct
11 Correct 2 ms 5468 KB Output is correct
12 Correct 2 ms 5572 KB Output is correct
13 Correct 2 ms 5468 KB Output is correct
14 Correct 2 ms 5468 KB Output is correct
15 Correct 2 ms 5468 KB Output is correct
16 Correct 2 ms 5468 KB Output is correct
17 Correct 2 ms 7512 KB Output is correct
18 Correct 4 ms 13912 KB Output is correct
19 Correct 4 ms 13660 KB Output is correct
20 Correct 3 ms 13660 KB Output is correct
21 Correct 3 ms 13660 KB Output is correct
22 Correct 5 ms 13852 KB Output is correct
23 Correct 5 ms 13656 KB Output is correct
24 Correct 4 ms 13812 KB Output is correct
25 Correct 5 ms 13660 KB Output is correct
26 Correct 5 ms 13656 KB Output is correct
27 Correct 4 ms 13660 KB Output is correct
28 Correct 4 ms 13660 KB Output is correct
29 Correct 140 ms 100184 KB Output is correct
30 Correct 194 ms 101688 KB Output is correct
31 Correct 60 ms 100856 KB Output is correct
32 Correct 20 ms 100444 KB Output is correct
33 Correct 21 ms 100212 KB Output is correct
34 Correct 247 ms 101800 KB Output is correct
35 Correct 279 ms 101716 KB Output is correct
36 Correct 23 ms 100516 KB Output is correct
37 Incorrect 91 ms 100672 KB Output isn't correct
38 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5468 KB Output is correct
2 Correct 2 ms 5468 KB Output is correct
3 Correct 2 ms 5468 KB Output is correct
4 Correct 2 ms 5468 KB Output is correct
5 Correct 2 ms 5468 KB Output is correct
6 Correct 2 ms 5468 KB Output is correct
7 Correct 2 ms 5464 KB Output is correct
8 Correct 2 ms 5468 KB Output is correct
9 Correct 2 ms 5468 KB Output is correct
10 Correct 3 ms 5724 KB Output is correct
11 Correct 2 ms 5468 KB Output is correct
12 Correct 2 ms 5572 KB Output is correct
13 Correct 2 ms 5468 KB Output is correct
14 Correct 2 ms 5468 KB Output is correct
15 Correct 2 ms 5468 KB Output is correct
16 Correct 2 ms 5468 KB Output is correct
17 Correct 2 ms 7512 KB Output is correct
18 Correct 4 ms 13912 KB Output is correct
19 Correct 4 ms 13660 KB Output is correct
20 Correct 3 ms 13660 KB Output is correct
21 Correct 3 ms 13660 KB Output is correct
22 Correct 5 ms 13852 KB Output is correct
23 Correct 5 ms 13656 KB Output is correct
24 Correct 4 ms 13812 KB Output is correct
25 Correct 5 ms 13660 KB Output is correct
26 Correct 5 ms 13656 KB Output is correct
27 Correct 4 ms 13660 KB Output is correct
28 Correct 4 ms 13660 KB Output is correct
29 Correct 140 ms 100184 KB Output is correct
30 Correct 194 ms 101688 KB Output is correct
31 Correct 60 ms 100856 KB Output is correct
32 Correct 20 ms 100444 KB Output is correct
33 Correct 21 ms 100212 KB Output is correct
34 Correct 247 ms 101800 KB Output is correct
35 Correct 279 ms 101716 KB Output is correct
36 Correct 23 ms 100516 KB Output is correct
37 Incorrect 91 ms 100672 KB Output isn't correct
38 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5468 KB Output is correct
2 Correct 2 ms 5468 KB Output is correct
3 Correct 2 ms 5468 KB Output is correct
4 Correct 2 ms 5468 KB Output is correct
5 Correct 2 ms 5468 KB Output is correct
6 Correct 2 ms 5468 KB Output is correct
7 Correct 2 ms 5464 KB Output is correct
8 Correct 2 ms 5468 KB Output is correct
9 Correct 2 ms 5468 KB Output is correct
10 Correct 3 ms 5724 KB Output is correct
11 Correct 2 ms 5468 KB Output is correct
12 Correct 2 ms 5572 KB Output is correct
13 Correct 2 ms 5468 KB Output is correct
14 Correct 2 ms 5468 KB Output is correct
15 Correct 2 ms 5468 KB Output is correct
16 Correct 2 ms 5468 KB Output is correct
17 Correct 2 ms 7512 KB Output is correct
18 Correct 4 ms 13912 KB Output is correct
19 Correct 4 ms 13660 KB Output is correct
20 Correct 3 ms 13660 KB Output is correct
21 Correct 3 ms 13660 KB Output is correct
22 Correct 5 ms 13852 KB Output is correct
23 Correct 5 ms 13656 KB Output is correct
24 Correct 4 ms 13812 KB Output is correct
25 Correct 5 ms 13660 KB Output is correct
26 Correct 5 ms 13656 KB Output is correct
27 Correct 4 ms 13660 KB Output is correct
28 Correct 4 ms 13660 KB Output is correct
29 Correct 140 ms 100184 KB Output is correct
30 Correct 194 ms 101688 KB Output is correct
31 Correct 60 ms 100856 KB Output is correct
32 Correct 20 ms 100444 KB Output is correct
33 Correct 21 ms 100212 KB Output is correct
34 Correct 247 ms 101800 KB Output is correct
35 Correct 279 ms 101716 KB Output is correct
36 Correct 23 ms 100516 KB Output is correct
37 Incorrect 91 ms 100672 KB Output isn't correct
38 Halted 0 ms 0 KB -