Submission #746273

# Submission time Handle Problem Language Result Execution time Memory
746273 2023-05-22T06:36:58 Z baluteshih Chorus (JOI23_chorus) C++14
40 / 100
85 ms 2296 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define X first
#define Y second
#define SZ(a) ((int)a.size())
#define ALL(v) v.begin(), v.end()
#define pb push_back

int lft[1000005];

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    int n, k;
    string s;
    cin >> n >> k >> s;
    if (n > 500) return 0;

    int cntA = 0, cntB = 0;
    for (int i = 0; i < n + n; ++i) {
        if (s[i] == 'B') ++cntB;
        else lft[++cntA] = cntB;
    }

    const ll INF = 1e18;
    vector<vector<ll>> dp(k + 1, vector<ll>(n + 1, INF));
    ll fin = INF;
    dp[0][0] = 0;
    for (int i = 0; i < k; ++i) {
        for (int j = 1; j <= n; ++j) {
            ll sum = 0;
            for (int p = j; p <= n; ++p) {
                sum += max(0, lft[p] - (j - 1));
                dp[i + 1][p] = min(dp[i + 1][p], dp[i][j - 1] + sum);
            }
        }
        fin = min(fin, dp[i + 1][n]);
    }

    cout << fin << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 300 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 300 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 15 ms 596 KB Output is correct
19 Correct 43 ms 1364 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 81 ms 2260 KB Output is correct
23 Correct 85 ms 2296 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 82 ms 2260 KB Output is correct
26 Correct 70 ms 1960 KB Output is correct
27 Correct 27 ms 980 KB Output is correct
28 Correct 27 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 300 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 15 ms 596 KB Output is correct
19 Correct 43 ms 1364 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 81 ms 2260 KB Output is correct
23 Correct 85 ms 2296 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 82 ms 2260 KB Output is correct
26 Correct 70 ms 1960 KB Output is correct
27 Correct 27 ms 980 KB Output is correct
28 Correct 27 ms 980 KB Output is correct
29 Incorrect 0 ms 340 KB Output isn't correct
30 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 300 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 15 ms 596 KB Output is correct
19 Correct 43 ms 1364 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 81 ms 2260 KB Output is correct
23 Correct 85 ms 2296 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 82 ms 2260 KB Output is correct
26 Correct 70 ms 1960 KB Output is correct
27 Correct 27 ms 980 KB Output is correct
28 Correct 27 ms 980 KB Output is correct
29 Incorrect 0 ms 340 KB Output isn't correct
30 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 300 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 15 ms 596 KB Output is correct
19 Correct 43 ms 1364 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 81 ms 2260 KB Output is correct
23 Correct 85 ms 2296 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 82 ms 2260 KB Output is correct
26 Correct 70 ms 1960 KB Output is correct
27 Correct 27 ms 980 KB Output is correct
28 Correct 27 ms 980 KB Output is correct
29 Incorrect 0 ms 340 KB Output isn't correct
30 Halted 0 ms 0 KB -