# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1094347 |
2024-09-29T11:09:45 Z |
_8_8_ |
Chorus (JOI23_chorus) |
C++17 |
|
2622 ms |
117760 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 5e3 + 12, MOD = (int)1e9 + 7;
int n, k, x[N], y[N], pref[ 2 * N], col[N], opt[N];
ll dp[N], c[N][N];
void prec() {
for(int i = 1; i <= n; i++) {
for(int j = i; j >= 1; j--) {
c[j][i] = c[j + 1][i];
if(y[j] <= x[i]) {
c[j][i] += pref[x[i]] - pref[y[j] - 1];;
}
}
}
for(int i = 1; i < n; i++) {
for(int j = 1; j < n; j++) {
assert(c[i][j + 1] + c[i + 1][j] >= c[i][j] + c[i + 1][j + 1]);
}
}
}
pair<ll, ll> calc_slow(ll pen) {
for(int i = 1; i <= n; i++) {
dp[i] = 1e18;
col[i] = n + 1;
for(int j = i; j >= 1; j--) {
if(pref[y[j]] > pref[x[i]] ) continue;
if(dp[j - 1] + c[j][i] + pen <= dp[i]) {
dp[i] = dp[j - 1] + c[j][i] + pen;
col[i] = col[j - 1] + 1;
opt[i] = j;
}
}
}
return {dp[n], col[n]};
}
// pair<ll, ll> calc(ll pen) {
// for(int i = 1; i <= n; i++) {
// }
// }
void test() {
cin >> n >> k;
int _x = 0, _y = 0;
for(int i = 1; i <= n + n; i++) {
char a;
cin >> a;
pref[i] = pref[i - 1];
if(a == 'A') {
x[++_x] = i;
pref[i]++;
} else {
y[++_y] = i;
}
}
prec();
ll l = -1, r = 1e12, res;
while(r - l > 1) {
ll mid = (l + r) / 2;
auto [val, t] = calc_slow(mid);
if(t <= k) {
r = mid;
res = val - k * 1ll * mid;
} else {
l = mid;
}
}
cout << res << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int t = 1;
// cin >> t;
while(t--)
test();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
432 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
416 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
420 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
432 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
416 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
420 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
1116 KB |
Output is correct |
18 |
Correct |
9 ms |
3532 KB |
Output is correct |
19 |
Correct |
8 ms |
3420 KB |
Output is correct |
20 |
Correct |
9 ms |
3420 KB |
Output is correct |
21 |
Correct |
9 ms |
3420 KB |
Output is correct |
22 |
Correct |
9 ms |
3528 KB |
Output is correct |
23 |
Correct |
9 ms |
3420 KB |
Output is correct |
24 |
Correct |
11 ms |
3416 KB |
Output is correct |
25 |
Correct |
8 ms |
3532 KB |
Output is correct |
26 |
Correct |
9 ms |
3420 KB |
Output is correct |
27 |
Correct |
9 ms |
3512 KB |
Output is correct |
28 |
Correct |
9 ms |
3364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
432 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
416 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
420 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
1116 KB |
Output is correct |
18 |
Correct |
9 ms |
3532 KB |
Output is correct |
19 |
Correct |
8 ms |
3420 KB |
Output is correct |
20 |
Correct |
9 ms |
3420 KB |
Output is correct |
21 |
Correct |
9 ms |
3420 KB |
Output is correct |
22 |
Correct |
9 ms |
3528 KB |
Output is correct |
23 |
Correct |
9 ms |
3420 KB |
Output is correct |
24 |
Correct |
11 ms |
3416 KB |
Output is correct |
25 |
Correct |
8 ms |
3532 KB |
Output is correct |
26 |
Correct |
9 ms |
3420 KB |
Output is correct |
27 |
Correct |
9 ms |
3512 KB |
Output is correct |
28 |
Correct |
9 ms |
3364 KB |
Output is correct |
29 |
Correct |
2261 ms |
114420 KB |
Output is correct |
30 |
Correct |
2238 ms |
117588 KB |
Output is correct |
31 |
Correct |
2326 ms |
117704 KB |
Output is correct |
32 |
Correct |
2410 ms |
117584 KB |
Output is correct |
33 |
Correct |
2458 ms |
117588 KB |
Output is correct |
34 |
Correct |
2536 ms |
117580 KB |
Output is correct |
35 |
Correct |
2356 ms |
117584 KB |
Output is correct |
36 |
Correct |
2622 ms |
117588 KB |
Output is correct |
37 |
Correct |
2522 ms |
117584 KB |
Output is correct |
38 |
Correct |
2545 ms |
117760 KB |
Output is correct |
39 |
Correct |
2403 ms |
117588 KB |
Output is correct |
40 |
Correct |
2354 ms |
117552 KB |
Output is correct |
41 |
Correct |
2461 ms |
117368 KB |
Output is correct |
42 |
Correct |
1115 ms |
117584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
432 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
416 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
420 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
1116 KB |
Output is correct |
18 |
Correct |
9 ms |
3532 KB |
Output is correct |
19 |
Correct |
8 ms |
3420 KB |
Output is correct |
20 |
Correct |
9 ms |
3420 KB |
Output is correct |
21 |
Correct |
9 ms |
3420 KB |
Output is correct |
22 |
Correct |
9 ms |
3528 KB |
Output is correct |
23 |
Correct |
9 ms |
3420 KB |
Output is correct |
24 |
Correct |
11 ms |
3416 KB |
Output is correct |
25 |
Correct |
8 ms |
3532 KB |
Output is correct |
26 |
Correct |
9 ms |
3420 KB |
Output is correct |
27 |
Correct |
9 ms |
3512 KB |
Output is correct |
28 |
Correct |
9 ms |
3364 KB |
Output is correct |
29 |
Correct |
2261 ms |
114420 KB |
Output is correct |
30 |
Correct |
2238 ms |
117588 KB |
Output is correct |
31 |
Correct |
2326 ms |
117704 KB |
Output is correct |
32 |
Correct |
2410 ms |
117584 KB |
Output is correct |
33 |
Correct |
2458 ms |
117588 KB |
Output is correct |
34 |
Correct |
2536 ms |
117580 KB |
Output is correct |
35 |
Correct |
2356 ms |
117584 KB |
Output is correct |
36 |
Correct |
2622 ms |
117588 KB |
Output is correct |
37 |
Correct |
2522 ms |
117584 KB |
Output is correct |
38 |
Correct |
2545 ms |
117760 KB |
Output is correct |
39 |
Correct |
2403 ms |
117588 KB |
Output is correct |
40 |
Correct |
2354 ms |
117552 KB |
Output is correct |
41 |
Correct |
2461 ms |
117368 KB |
Output is correct |
42 |
Correct |
1115 ms |
117584 KB |
Output is correct |
43 |
Runtime error |
4 ms |
604 KB |
Execution killed with signal 11 |
44 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
432 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
416 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
420 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
1116 KB |
Output is correct |
18 |
Correct |
9 ms |
3532 KB |
Output is correct |
19 |
Correct |
8 ms |
3420 KB |
Output is correct |
20 |
Correct |
9 ms |
3420 KB |
Output is correct |
21 |
Correct |
9 ms |
3420 KB |
Output is correct |
22 |
Correct |
9 ms |
3528 KB |
Output is correct |
23 |
Correct |
9 ms |
3420 KB |
Output is correct |
24 |
Correct |
11 ms |
3416 KB |
Output is correct |
25 |
Correct |
8 ms |
3532 KB |
Output is correct |
26 |
Correct |
9 ms |
3420 KB |
Output is correct |
27 |
Correct |
9 ms |
3512 KB |
Output is correct |
28 |
Correct |
9 ms |
3364 KB |
Output is correct |
29 |
Correct |
2261 ms |
114420 KB |
Output is correct |
30 |
Correct |
2238 ms |
117588 KB |
Output is correct |
31 |
Correct |
2326 ms |
117704 KB |
Output is correct |
32 |
Correct |
2410 ms |
117584 KB |
Output is correct |
33 |
Correct |
2458 ms |
117588 KB |
Output is correct |
34 |
Correct |
2536 ms |
117580 KB |
Output is correct |
35 |
Correct |
2356 ms |
117584 KB |
Output is correct |
36 |
Correct |
2622 ms |
117588 KB |
Output is correct |
37 |
Correct |
2522 ms |
117584 KB |
Output is correct |
38 |
Correct |
2545 ms |
117760 KB |
Output is correct |
39 |
Correct |
2403 ms |
117588 KB |
Output is correct |
40 |
Correct |
2354 ms |
117552 KB |
Output is correct |
41 |
Correct |
2461 ms |
117368 KB |
Output is correct |
42 |
Correct |
1115 ms |
117584 KB |
Output is correct |
43 |
Runtime error |
4 ms |
604 KB |
Execution killed with signal 11 |
44 |
Halted |
0 ms |
0 KB |
- |