답안 #906219

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
906219 2024-01-13T18:58:51 Z LucaIlie Chorus (JOI23_chorus) C++17
40 / 100
7000 ms 96932 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 5e3;
int a[MAX_N + 1], dp[MAX_N + 1][MAX_N + 1];

int main() {
    int n, k;

    cin >> n >> k;

    int countB = 0, countA = 0;
    for ( int i = 0; i < 2 * n; i++ ) {
        char ch;
        cin >> ch;
        if ( ch == 'A' )
            countA++;
        else {
            countB++;
            a[countB] = countA;
        }
    }

    for ( int i = 1; i <= n; i++ )
        dp[i][0] = n * n;
    for ( int l = 1; l <= k; l++ ) {
        for ( int i = 1; i <= n; i++ ) {
            dp[i][l] = n * n;
            int swapsAdded = 0, j;
            for ( j = i - 1; j >= 0 && a[j + 1] >= i; j-- )
                dp[i][l] = min( dp[i][l], dp[j][l - 1] );
            for ( ; j >= 0; j-- ) {
                swapsAdded += i - a[j + 1];
                dp[i][l] = min( dp[i][l], dp[j][l - 1] + swapsAdded );
            }
        }
    }

    cout << dp[n][k];

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 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 2392 KB Output is correct
11 Correct 1 ms 2392 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 2392 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 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 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 2392 KB Output is correct
11 Correct 1 ms 2392 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 2392 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 2 ms 4444 KB Output is correct
18 Correct 14 ms 10740 KB Output is correct
19 Correct 37 ms 10588 KB Output is correct
20 Correct 2 ms 10588 KB Output is correct
21 Correct 3 ms 10588 KB Output is correct
22 Correct 70 ms 10736 KB Output is correct
23 Correct 69 ms 10588 KB Output is correct
24 Correct 3 ms 10588 KB Output is correct
25 Correct 81 ms 10832 KB Output is correct
26 Correct 60 ms 10584 KB Output is correct
27 Correct 24 ms 10588 KB Output is correct
28 Correct 24 ms 10744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 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 2392 KB Output is correct
11 Correct 1 ms 2392 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 2392 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 2 ms 4444 KB Output is correct
18 Correct 14 ms 10740 KB Output is correct
19 Correct 37 ms 10588 KB Output is correct
20 Correct 2 ms 10588 KB Output is correct
21 Correct 3 ms 10588 KB Output is correct
22 Correct 70 ms 10736 KB Output is correct
23 Correct 69 ms 10588 KB Output is correct
24 Correct 3 ms 10588 KB Output is correct
25 Correct 81 ms 10832 KB Output is correct
26 Correct 60 ms 10584 KB Output is correct
27 Correct 24 ms 10588 KB Output is correct
28 Correct 24 ms 10744 KB Output is correct
29 Execution timed out 7062 ms 96932 KB Time limit exceeded
30 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 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 2392 KB Output is correct
11 Correct 1 ms 2392 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 2392 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 2 ms 4444 KB Output is correct
18 Correct 14 ms 10740 KB Output is correct
19 Correct 37 ms 10588 KB Output is correct
20 Correct 2 ms 10588 KB Output is correct
21 Correct 3 ms 10588 KB Output is correct
22 Correct 70 ms 10736 KB Output is correct
23 Correct 69 ms 10588 KB Output is correct
24 Correct 3 ms 10588 KB Output is correct
25 Correct 81 ms 10832 KB Output is correct
26 Correct 60 ms 10584 KB Output is correct
27 Correct 24 ms 10588 KB Output is correct
28 Correct 24 ms 10744 KB Output is correct
29 Execution timed out 7062 ms 96932 KB Time limit exceeded
30 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 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 2392 KB Output is correct
11 Correct 1 ms 2392 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 2392 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 2 ms 4444 KB Output is correct
18 Correct 14 ms 10740 KB Output is correct
19 Correct 37 ms 10588 KB Output is correct
20 Correct 2 ms 10588 KB Output is correct
21 Correct 3 ms 10588 KB Output is correct
22 Correct 70 ms 10736 KB Output is correct
23 Correct 69 ms 10588 KB Output is correct
24 Correct 3 ms 10588 KB Output is correct
25 Correct 81 ms 10832 KB Output is correct
26 Correct 60 ms 10584 KB Output is correct
27 Correct 24 ms 10588 KB Output is correct
28 Correct 24 ms 10744 KB Output is correct
29 Execution timed out 7062 ms 96932 KB Time limit exceeded
30 Halted 0 ms 0 KB -