답안 #906437

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
906437 2024-01-14T09:44:52 Z LucaIlie Chorus (JOI23_chorus) C++17
40 / 100
7000 ms 193516 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 5e3;
int a[MAX_N + 1];
long long sumA[MAX_N + 1], countLowerA[MAX_N + 1], sumLowerA[MAX_N + 1], minSwaps[MAX_N + 1][MAX_N + 1];

int main() {
    int n, k, swaps;

    cin >> n >> k;

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

    for ( int i = 1; i <= n; i++ )
        minSwaps[i][0] = n * n;
    for ( int l = 1; l <= k; l++ ) {
        for ( int i = 1; i <= n; i++ ) {
            minSwaps[i][l] = n * n;
            for ( int j = i - 1; j >= 0; j-- )
                minSwaps[i][l] = min( minSwaps[i][l], minSwaps[j][l - 1] + i * (countLowerA[i] - j) - (sumLowerA[i] - sumA[j]) );
        }
    }

    cout << swaps + minSwaps[n][k];

    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 348 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 348 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 1 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 348 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 348 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 1 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 3 ms 8540 KB Output is correct
18 Correct 16 ms 21012 KB Output is correct
19 Correct 39 ms 20980 KB Output is correct
20 Correct 4 ms 20824 KB Output is correct
21 Correct 5 ms 20828 KB Output is correct
22 Correct 76 ms 21004 KB Output is correct
23 Correct 72 ms 21000 KB Output is correct
24 Correct 5 ms 20824 KB Output is correct
25 Correct 69 ms 21004 KB Output is correct
26 Correct 59 ms 20824 KB Output is correct
27 Correct 26 ms 20992 KB Output is correct
28 Correct 26 ms 20828 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 348 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 348 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 1 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 3 ms 8540 KB Output is correct
18 Correct 16 ms 21012 KB Output is correct
19 Correct 39 ms 20980 KB Output is correct
20 Correct 4 ms 20824 KB Output is correct
21 Correct 5 ms 20828 KB Output is correct
22 Correct 76 ms 21004 KB Output is correct
23 Correct 72 ms 21000 KB Output is correct
24 Correct 5 ms 20824 KB Output is correct
25 Correct 69 ms 21004 KB Output is correct
26 Correct 59 ms 20824 KB Output is correct
27 Correct 26 ms 20992 KB Output is correct
28 Correct 26 ms 20828 KB Output is correct
29 Execution timed out 7049 ms 193516 KB Time limit exceeded
30 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 348 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 348 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 1 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 3 ms 8540 KB Output is correct
18 Correct 16 ms 21012 KB Output is correct
19 Correct 39 ms 20980 KB Output is correct
20 Correct 4 ms 20824 KB Output is correct
21 Correct 5 ms 20828 KB Output is correct
22 Correct 76 ms 21004 KB Output is correct
23 Correct 72 ms 21000 KB Output is correct
24 Correct 5 ms 20824 KB Output is correct
25 Correct 69 ms 21004 KB Output is correct
26 Correct 59 ms 20824 KB Output is correct
27 Correct 26 ms 20992 KB Output is correct
28 Correct 26 ms 20828 KB Output is correct
29 Execution timed out 7049 ms 193516 KB Time limit exceeded
30 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 348 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 348 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 1 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 3 ms 8540 KB Output is correct
18 Correct 16 ms 21012 KB Output is correct
19 Correct 39 ms 20980 KB Output is correct
20 Correct 4 ms 20824 KB Output is correct
21 Correct 5 ms 20828 KB Output is correct
22 Correct 76 ms 21004 KB Output is correct
23 Correct 72 ms 21000 KB Output is correct
24 Correct 5 ms 20824 KB Output is correct
25 Correct 69 ms 21004 KB Output is correct
26 Correct 59 ms 20824 KB Output is correct
27 Correct 26 ms 20992 KB Output is correct
28 Correct 26 ms 20828 KB Output is correct
29 Execution timed out 7049 ms 193516 KB Time limit exceeded
30 Halted 0 ms 0 KB -