# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
789141 |
2023-07-21T06:18:16 Z |
반딧불(#10041) |
Chorus (JOI23_chorus) |
C++17 |
|
857 ms |
449160 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void input();
void solve();
int main(){
input();
solve();
}
int n, k;
ll arr[1000002]; /// A = ( = 1, B = ) = -1
ll revArr[1000002]; /// revArr[x]: arr[i] >= x�� �Ǵ� �ּ� i
ll sum[1000002];
char str[2000002];
void input(){
scanf("%d %d", &n, &k);
scanf("%s", str+1);
int aCnt = 0, bCnt = 0;
for(int i=1; i<=n+n; i++){
if(str[i] == 'A') ++aCnt;
else arr[++bCnt] = aCnt;
}
arr[n+1] = n+1;
int pnt = 1;
for(int i=arr[1]; i<=n; i++){
while(arr[pnt] < i) pnt++;
revArr[i] = pnt;
}
for(int i=1; i<=n; i++) sum[i] = sum[i-1] + arr[i];
}
ll DP[5002][5002];
ll cost(int s, int e){
int r = min(e, (int)revArr[e] - 1);
if(s>r) return 0;
return ll(e) * (r-s+1) - (sum[r] - sum[s-1]);
}
void dnc(int d, int l, int r, int s, int e){
if(r<l) return;
int m = (l+r)>>1;
ll minV = LLONG_MAX; int minIdx = -1;
for(int i=s; i<=e && i<m; i++){
ll val = DP[d-1][i] + cost(i+1, m);
if(minV > val) minV = val, minIdx = i;
}
DP[d][m] = minV;
// printf("DP[%d][%d]: %lld\n", d, m, minV);
dnc(d, l, m-1, s, minIdx);
dnc(d, m+1, r, minIdx, e);
}
void solve(){
for(int i=0; i<=k; i++) for(int j=0; j<=n; j++) DP[i][j] = 1e18;
DP[0][0] = 0;
for(int j=1; j<=k; j++){
dnc(j, 1, n, 0, n-1);
}
printf("%lld", DP[k][n]);
}
Compilation message
chorus.cpp: In function 'void input()':
chorus.cpp:22:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
22 | scanf("%d %d", &n, &k);
| ~~~~~^~~~~~~~~~~~~~~~~
chorus.cpp:23:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
23 | scanf("%s", str+1);
| ~~~~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
308 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
308 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
308 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
308 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
308 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
308 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
596 KB |
Output is correct |
18 |
Correct |
2 ms |
1076 KB |
Output is correct |
19 |
Correct |
5 ms |
2516 KB |
Output is correct |
20 |
Correct |
1 ms |
300 KB |
Output is correct |
21 |
Correct |
1 ms |
304 KB |
Output is correct |
22 |
Correct |
6 ms |
4308 KB |
Output is correct |
23 |
Correct |
8 ms |
4348 KB |
Output is correct |
24 |
Correct |
1 ms |
436 KB |
Output is correct |
25 |
Correct |
6 ms |
4308 KB |
Output is correct |
26 |
Correct |
5 ms |
3668 KB |
Output is correct |
27 |
Correct |
2 ms |
1620 KB |
Output is correct |
28 |
Correct |
2 ms |
1620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
308 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
308 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
308 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
596 KB |
Output is correct |
18 |
Correct |
2 ms |
1076 KB |
Output is correct |
19 |
Correct |
5 ms |
2516 KB |
Output is correct |
20 |
Correct |
1 ms |
300 KB |
Output is correct |
21 |
Correct |
1 ms |
304 KB |
Output is correct |
22 |
Correct |
6 ms |
4308 KB |
Output is correct |
23 |
Correct |
8 ms |
4348 KB |
Output is correct |
24 |
Correct |
1 ms |
436 KB |
Output is correct |
25 |
Correct |
6 ms |
4308 KB |
Output is correct |
26 |
Correct |
5 ms |
3668 KB |
Output is correct |
27 |
Correct |
2 ms |
1620 KB |
Output is correct |
28 |
Correct |
2 ms |
1620 KB |
Output is correct |
29 |
Correct |
241 ms |
80564 KB |
Output is correct |
30 |
Correct |
857 ms |
170112 KB |
Output is correct |
31 |
Correct |
217 ms |
40788 KB |
Output is correct |
32 |
Correct |
1 ms |
468 KB |
Output is correct |
33 |
Correct |
1 ms |
468 KB |
Output is correct |
34 |
Correct |
518 ms |
196224 KB |
Output is correct |
35 |
Correct |
539 ms |
196260 KB |
Output is correct |
36 |
Correct |
3 ms |
852 KB |
Output is correct |
37 |
Correct |
219 ms |
39668 KB |
Output is correct |
38 |
Correct |
437 ms |
162508 KB |
Output is correct |
39 |
Correct |
378 ms |
93636 KB |
Output is correct |
40 |
Correct |
208 ms |
65760 KB |
Output is correct |
41 |
Correct |
200 ms |
65764 KB |
Output is correct |
42 |
Correct |
237 ms |
65684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
308 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
308 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
308 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
596 KB |
Output is correct |
18 |
Correct |
2 ms |
1076 KB |
Output is correct |
19 |
Correct |
5 ms |
2516 KB |
Output is correct |
20 |
Correct |
1 ms |
300 KB |
Output is correct |
21 |
Correct |
1 ms |
304 KB |
Output is correct |
22 |
Correct |
6 ms |
4308 KB |
Output is correct |
23 |
Correct |
8 ms |
4348 KB |
Output is correct |
24 |
Correct |
1 ms |
436 KB |
Output is correct |
25 |
Correct |
6 ms |
4308 KB |
Output is correct |
26 |
Correct |
5 ms |
3668 KB |
Output is correct |
27 |
Correct |
2 ms |
1620 KB |
Output is correct |
28 |
Correct |
2 ms |
1620 KB |
Output is correct |
29 |
Correct |
241 ms |
80564 KB |
Output is correct |
30 |
Correct |
857 ms |
170112 KB |
Output is correct |
31 |
Correct |
217 ms |
40788 KB |
Output is correct |
32 |
Correct |
1 ms |
468 KB |
Output is correct |
33 |
Correct |
1 ms |
468 KB |
Output is correct |
34 |
Correct |
518 ms |
196224 KB |
Output is correct |
35 |
Correct |
539 ms |
196260 KB |
Output is correct |
36 |
Correct |
3 ms |
852 KB |
Output is correct |
37 |
Correct |
219 ms |
39668 KB |
Output is correct |
38 |
Correct |
437 ms |
162508 KB |
Output is correct |
39 |
Correct |
378 ms |
93636 KB |
Output is correct |
40 |
Correct |
208 ms |
65760 KB |
Output is correct |
41 |
Correct |
200 ms |
65764 KB |
Output is correct |
42 |
Correct |
237 ms |
65684 KB |
Output is correct |
43 |
Runtime error |
546 ms |
449160 KB |
Execution killed with signal 11 |
44 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
308 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
308 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
308 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
596 KB |
Output is correct |
18 |
Correct |
2 ms |
1076 KB |
Output is correct |
19 |
Correct |
5 ms |
2516 KB |
Output is correct |
20 |
Correct |
1 ms |
300 KB |
Output is correct |
21 |
Correct |
1 ms |
304 KB |
Output is correct |
22 |
Correct |
6 ms |
4308 KB |
Output is correct |
23 |
Correct |
8 ms |
4348 KB |
Output is correct |
24 |
Correct |
1 ms |
436 KB |
Output is correct |
25 |
Correct |
6 ms |
4308 KB |
Output is correct |
26 |
Correct |
5 ms |
3668 KB |
Output is correct |
27 |
Correct |
2 ms |
1620 KB |
Output is correct |
28 |
Correct |
2 ms |
1620 KB |
Output is correct |
29 |
Correct |
241 ms |
80564 KB |
Output is correct |
30 |
Correct |
857 ms |
170112 KB |
Output is correct |
31 |
Correct |
217 ms |
40788 KB |
Output is correct |
32 |
Correct |
1 ms |
468 KB |
Output is correct |
33 |
Correct |
1 ms |
468 KB |
Output is correct |
34 |
Correct |
518 ms |
196224 KB |
Output is correct |
35 |
Correct |
539 ms |
196260 KB |
Output is correct |
36 |
Correct |
3 ms |
852 KB |
Output is correct |
37 |
Correct |
219 ms |
39668 KB |
Output is correct |
38 |
Correct |
437 ms |
162508 KB |
Output is correct |
39 |
Correct |
378 ms |
93636 KB |
Output is correct |
40 |
Correct |
208 ms |
65760 KB |
Output is correct |
41 |
Correct |
200 ms |
65764 KB |
Output is correct |
42 |
Correct |
237 ms |
65684 KB |
Output is correct |
43 |
Runtime error |
546 ms |
449160 KB |
Execution killed with signal 11 |
44 |
Halted |
0 ms |
0 KB |
- |