답안 #961888

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
961888 2024-04-12T16:49:39 Z RaresFelix Chorus (JOI23_chorus) C++17
40 / 100
7000 ms 268864 KB
#include <bits/stdc++.h>
//#pragma GCC optimize("O3")
//#pragma GCC target("avx,avx2,fma")

#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

#define int ll

using ll = long long;
using ld = long double;  // or double, if TL is tight
using str = string; 
using ii = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;


signed main() {
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int n, k;
    string s;
    cin >> n >> k >> s;
    int nrB = 0;
    vi A;
    for(int i = 0; i < 2 * n; ++i) {
        if(s[i] == 'B') ++nrB;
        else A.push_back(nrB);
    }
    const int INF = 1e9;
    vector<vi> Cost(n, vi(n, 0));
    for(int i = 0; i < n; ++i) {
        for(int j = i; j < n; ++j) {
            Cost[i][j] = max(0ll, A[j] - i);
            if(j) Cost[i][j] += Cost[i][j - 1];
        }
    }
    vector<vi> DP(n, vi(k + 1, INF));
    for(int i = 0; i < n; ++i) {
        for(int j = 1; j <= k; ++j) {
            if(j == 1) DP[i][j] = Cost[0][i];
            for(int ant = 1; ant <= i; ++ant) {
                DP[i][j] = min(DP[i][j], DP[ant - 1][j - 1] + Cost[ant][i]);
            }
        }
    }
    cout << DP[n - 1][k] << "\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 456 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 452 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 456 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 452 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 19 ms 2652 KB Output is correct
19 Correct 61 ms 3516 KB Output is correct
20 Correct 2 ms 2396 KB Output is correct
21 Correct 2 ms 2396 KB Output is correct
22 Correct 104 ms 4400 KB Output is correct
23 Correct 111 ms 4400 KB Output is correct
24 Correct 4 ms 2396 KB Output is correct
25 Correct 106 ms 4400 KB Output is correct
26 Correct 99 ms 4072 KB Output is correct
27 Correct 35 ms 2904 KB Output is correct
28 Correct 36 ms 2908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 456 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 452 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 19 ms 2652 KB Output is correct
19 Correct 61 ms 3516 KB Output is correct
20 Correct 2 ms 2396 KB Output is correct
21 Correct 2 ms 2396 KB Output is correct
22 Correct 104 ms 4400 KB Output is correct
23 Correct 111 ms 4400 KB Output is correct
24 Correct 4 ms 2396 KB Output is correct
25 Correct 106 ms 4400 KB Output is correct
26 Correct 99 ms 4072 KB Output is correct
27 Correct 35 ms 2904 KB Output is correct
28 Correct 36 ms 2908 KB Output is correct
29 Execution timed out 7045 ms 268864 KB Time limit exceeded
30 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 456 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 452 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 19 ms 2652 KB Output is correct
19 Correct 61 ms 3516 KB Output is correct
20 Correct 2 ms 2396 KB Output is correct
21 Correct 2 ms 2396 KB Output is correct
22 Correct 104 ms 4400 KB Output is correct
23 Correct 111 ms 4400 KB Output is correct
24 Correct 4 ms 2396 KB Output is correct
25 Correct 106 ms 4400 KB Output is correct
26 Correct 99 ms 4072 KB Output is correct
27 Correct 35 ms 2904 KB Output is correct
28 Correct 36 ms 2908 KB Output is correct
29 Execution timed out 7045 ms 268864 KB Time limit exceeded
30 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 456 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 452 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 19 ms 2652 KB Output is correct
19 Correct 61 ms 3516 KB Output is correct
20 Correct 2 ms 2396 KB Output is correct
21 Correct 2 ms 2396 KB Output is correct
22 Correct 104 ms 4400 KB Output is correct
23 Correct 111 ms 4400 KB Output is correct
24 Correct 4 ms 2396 KB Output is correct
25 Correct 106 ms 4400 KB Output is correct
26 Correct 99 ms 4072 KB Output is correct
27 Correct 35 ms 2904 KB Output is correct
28 Correct 36 ms 2908 KB Output is correct
29 Execution timed out 7045 ms 268864 KB Time limit exceeded
30 Halted 0 ms 0 KB -