# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
796445 |
2023-07-28T11:47:05 Z |
Johann |
Chorus (JOI23_chorus) |
C++14 |
|
592 ms |
1048576 KB |
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
const ll INF = 1LL << 60;
int N, K;
vi S;
int cnt[2];
vi pos[2];
vvi dp;
vvi trans;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> N >> K;
string SS;
cin >> SS;
S.resize(2 * N);
for (int foo = 0; foo < 2; ++foo)
pos[foo].assign(N, -1);
for (int i = 0; i < 2 * N; ++i)
{
S[i] = (SS[i] == 'B');
pos[S[i]][cnt[S[i]]++] = i;
}
trans = vvi(N + 1, vi(N + 1, INF));
for (int i = 1; i <= N; ++i)
{
trans[i][i] = 0;
int border = 2 * i;
for (int j = i; j < N; ++j)
trans[i][j + 1] = trans[i][j] + max(0LL, pos[0][j] - border++);
}
dp = vvi(N + 1, vi(K + 1, INF));
dp[0][0] = 0;
dp[0][1] = 0;
for (int i = 0; i < N; ++i)
dp[i + 1][1] = dp[i][1] + pos[0][i] - i;
for (int k = 2; k <= K; ++k)
{
int idx = k - 1;
for (int j = k; j <= N; ++j)
{
for (int i = idx; i < j && dp[i][k - 1] <= dp[idx][k - 1] + trans[idx][j]; ++i)
if (dp[i][k - 1] + trans[i][j] <= dp[idx][k - 1] + trans[idx][j])
idx = i;
// while (idx + 1 < j && dp[idx][k - 1] + trans[idx][j] >= dp[idx + 1][k - 1] + trans[idx + 1][j])
// ++idx;
dp[j][k] = dp[idx][k - 1] + trans[idx][j];
}
}
cout << dp[N][K] << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 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 |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 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 |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
320 KB |
Output is correct |
17 |
Correct |
1 ms |
572 KB |
Output is correct |
18 |
Correct |
2 ms |
2644 KB |
Output is correct |
19 |
Correct |
2 ms |
3392 KB |
Output is correct |
20 |
Correct |
1 ms |
2260 KB |
Output is correct |
21 |
Correct |
2 ms |
2260 KB |
Output is correct |
22 |
Correct |
3 ms |
4180 KB |
Output is correct |
23 |
Correct |
3 ms |
4180 KB |
Output is correct |
24 |
Correct |
2 ms |
2260 KB |
Output is correct |
25 |
Correct |
3 ms |
4180 KB |
Output is correct |
26 |
Correct |
3 ms |
3924 KB |
Output is correct |
27 |
Correct |
2 ms |
2900 KB |
Output is correct |
28 |
Correct |
2 ms |
2884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 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 |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
320 KB |
Output is correct |
17 |
Correct |
1 ms |
572 KB |
Output is correct |
18 |
Correct |
2 ms |
2644 KB |
Output is correct |
19 |
Correct |
2 ms |
3392 KB |
Output is correct |
20 |
Correct |
1 ms |
2260 KB |
Output is correct |
21 |
Correct |
2 ms |
2260 KB |
Output is correct |
22 |
Correct |
3 ms |
4180 KB |
Output is correct |
23 |
Correct |
3 ms |
4180 KB |
Output is correct |
24 |
Correct |
2 ms |
2260 KB |
Output is correct |
25 |
Correct |
3 ms |
4180 KB |
Output is correct |
26 |
Correct |
3 ms |
3924 KB |
Output is correct |
27 |
Correct |
2 ms |
2900 KB |
Output is correct |
28 |
Correct |
2 ms |
2884 KB |
Output is correct |
29 |
Correct |
349 ms |
269116 KB |
Output is correct |
30 |
Correct |
450 ms |
366244 KB |
Output is correct |
31 |
Correct |
237 ms |
236876 KB |
Output is correct |
32 |
Correct |
80 ms |
196568 KB |
Output is correct |
33 |
Correct |
99 ms |
196636 KB |
Output is correct |
34 |
Correct |
534 ms |
392384 KB |
Output is correct |
35 |
Correct |
592 ms |
392388 KB |
Output is correct |
36 |
Correct |
108 ms |
196884 KB |
Output is correct |
37 |
Correct |
269 ms |
235700 KB |
Output is correct |
38 |
Correct |
435 ms |
358640 KB |
Output is correct |
39 |
Correct |
368 ms |
289804 KB |
Output is correct |
40 |
Correct |
307 ms |
261816 KB |
Output is correct |
41 |
Correct |
318 ms |
261800 KB |
Output is correct |
42 |
Correct |
205 ms |
261856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 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 |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
320 KB |
Output is correct |
17 |
Correct |
1 ms |
572 KB |
Output is correct |
18 |
Correct |
2 ms |
2644 KB |
Output is correct |
19 |
Correct |
2 ms |
3392 KB |
Output is correct |
20 |
Correct |
1 ms |
2260 KB |
Output is correct |
21 |
Correct |
2 ms |
2260 KB |
Output is correct |
22 |
Correct |
3 ms |
4180 KB |
Output is correct |
23 |
Correct |
3 ms |
4180 KB |
Output is correct |
24 |
Correct |
2 ms |
2260 KB |
Output is correct |
25 |
Correct |
3 ms |
4180 KB |
Output is correct |
26 |
Correct |
3 ms |
3924 KB |
Output is correct |
27 |
Correct |
2 ms |
2900 KB |
Output is correct |
28 |
Correct |
2 ms |
2884 KB |
Output is correct |
29 |
Correct |
349 ms |
269116 KB |
Output is correct |
30 |
Correct |
450 ms |
366244 KB |
Output is correct |
31 |
Correct |
237 ms |
236876 KB |
Output is correct |
32 |
Correct |
80 ms |
196568 KB |
Output is correct |
33 |
Correct |
99 ms |
196636 KB |
Output is correct |
34 |
Correct |
534 ms |
392384 KB |
Output is correct |
35 |
Correct |
592 ms |
392388 KB |
Output is correct |
36 |
Correct |
108 ms |
196884 KB |
Output is correct |
37 |
Correct |
269 ms |
235700 KB |
Output is correct |
38 |
Correct |
435 ms |
358640 KB |
Output is correct |
39 |
Correct |
368 ms |
289804 KB |
Output is correct |
40 |
Correct |
307 ms |
261816 KB |
Output is correct |
41 |
Correct |
318 ms |
261800 KB |
Output is correct |
42 |
Correct |
205 ms |
261856 KB |
Output is correct |
43 |
Runtime error |
537 ms |
1048576 KB |
Execution killed with signal 9 |
44 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 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 |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
320 KB |
Output is correct |
17 |
Correct |
1 ms |
572 KB |
Output is correct |
18 |
Correct |
2 ms |
2644 KB |
Output is correct |
19 |
Correct |
2 ms |
3392 KB |
Output is correct |
20 |
Correct |
1 ms |
2260 KB |
Output is correct |
21 |
Correct |
2 ms |
2260 KB |
Output is correct |
22 |
Correct |
3 ms |
4180 KB |
Output is correct |
23 |
Correct |
3 ms |
4180 KB |
Output is correct |
24 |
Correct |
2 ms |
2260 KB |
Output is correct |
25 |
Correct |
3 ms |
4180 KB |
Output is correct |
26 |
Correct |
3 ms |
3924 KB |
Output is correct |
27 |
Correct |
2 ms |
2900 KB |
Output is correct |
28 |
Correct |
2 ms |
2884 KB |
Output is correct |
29 |
Correct |
349 ms |
269116 KB |
Output is correct |
30 |
Correct |
450 ms |
366244 KB |
Output is correct |
31 |
Correct |
237 ms |
236876 KB |
Output is correct |
32 |
Correct |
80 ms |
196568 KB |
Output is correct |
33 |
Correct |
99 ms |
196636 KB |
Output is correct |
34 |
Correct |
534 ms |
392384 KB |
Output is correct |
35 |
Correct |
592 ms |
392388 KB |
Output is correct |
36 |
Correct |
108 ms |
196884 KB |
Output is correct |
37 |
Correct |
269 ms |
235700 KB |
Output is correct |
38 |
Correct |
435 ms |
358640 KB |
Output is correct |
39 |
Correct |
368 ms |
289804 KB |
Output is correct |
40 |
Correct |
307 ms |
261816 KB |
Output is correct |
41 |
Correct |
318 ms |
261800 KB |
Output is correct |
42 |
Correct |
205 ms |
261856 KB |
Output is correct |
43 |
Runtime error |
537 ms |
1048576 KB |
Execution killed with signal 9 |
44 |
Halted |
0 ms |
0 KB |
- |