# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1037891 |
2024-07-29T09:49:46 Z |
김은성(#10980) |
Chorus (JOI23_chorus) |
C++17 |
|
7000 ms |
17140 KB |
#include <bits/stdc++.h>
using namespace std;
char s[2000009];
typedef long long ll;
ll a[1000009], psum[1000009], dp[3009][3009];
ll cost(int k, int j){
int idx = lower_bound(a+k, a+j, k-1) - a;
//printf("k=%d j=%d idx=%d ret=%d\n", k, j, idx, psum[j-1] - psum[idx-1] - (k-1) * (j-idx));
return psum[j-1] - psum[idx-1] - (k-1) * (j-idx);
}
int main(){
int n, k, i, j, j2, cur = 0, cnt = 0;
scanf("%d %d", &n, &k);
scanf(" %s", s);
for(i=0; i<2*n; i++){
if(s[i] == 'A'){
a[++cnt] = cur;
//printf("a[%d]=%d\n", cnt, cur);
}
else
cur++;
}
for(i=1; i<=n; i++)
psum[i] = psum[i-1] + a[i];
for(j=1; j<=n+1; j++)
dp[1][j] = cost(1, j);
for(i=2; i<=k; i++){
for(j=1; j<=n+1; j++){
dp[i][j] = 1000000000;
for(j2=1; j2<j; j2++)
dp[i][j]= min(dp[i][j], dp[i-1][j2] + cost(j2, j));
}
}
printf("%d\n", dp[k][n+1]);
return 0;
}
Compilation message
chorus.cpp: In function 'int main()':
chorus.cpp:34:14: warning: format '%d' expects argument of type 'int', but argument 2 has type 'll' {aka 'long long int'} [-Wformat=]
34 | printf("%d\n", dp[k][n+1]);
| ~^ ~~~~~~~~~~
| | |
| int ll {aka long long int}
| %lld
chorus.cpp:13:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | scanf("%d %d", &n, &k);
| ~~~~~^~~~~~~~~~~~~~~~~
chorus.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | scanf(" %s", s);
| ~~~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
0 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
0 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
0 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
0 ms |
4444 KB |
Output is correct |
17 |
Correct |
9 ms |
6488 KB |
Output is correct |
18 |
Correct |
128 ms |
6492 KB |
Output is correct |
19 |
Correct |
398 ms |
12624 KB |
Output is correct |
20 |
Correct |
1 ms |
4440 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
515 ms |
16888 KB |
Output is correct |
23 |
Correct |
516 ms |
16892 KB |
Output is correct |
24 |
Correct |
13 ms |
6492 KB |
Output is correct |
25 |
Correct |
531 ms |
17140 KB |
Output is correct |
26 |
Correct |
411 ms |
14852 KB |
Output is correct |
27 |
Correct |
168 ms |
8692 KB |
Output is correct |
28 |
Correct |
161 ms |
8452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
0 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
0 ms |
4444 KB |
Output is correct |
17 |
Correct |
9 ms |
6488 KB |
Output is correct |
18 |
Correct |
128 ms |
6492 KB |
Output is correct |
19 |
Correct |
398 ms |
12624 KB |
Output is correct |
20 |
Correct |
1 ms |
4440 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
515 ms |
16888 KB |
Output is correct |
23 |
Correct |
516 ms |
16892 KB |
Output is correct |
24 |
Correct |
13 ms |
6492 KB |
Output is correct |
25 |
Correct |
531 ms |
17140 KB |
Output is correct |
26 |
Correct |
411 ms |
14852 KB |
Output is correct |
27 |
Correct |
168 ms |
8692 KB |
Output is correct |
28 |
Correct |
161 ms |
8452 KB |
Output is correct |
29 |
Execution timed out |
7070 ms |
6764 KB |
Time limit exceeded |
30 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
0 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
0 ms |
4444 KB |
Output is correct |
17 |
Correct |
9 ms |
6488 KB |
Output is correct |
18 |
Correct |
128 ms |
6492 KB |
Output is correct |
19 |
Correct |
398 ms |
12624 KB |
Output is correct |
20 |
Correct |
1 ms |
4440 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
515 ms |
16888 KB |
Output is correct |
23 |
Correct |
516 ms |
16892 KB |
Output is correct |
24 |
Correct |
13 ms |
6492 KB |
Output is correct |
25 |
Correct |
531 ms |
17140 KB |
Output is correct |
26 |
Correct |
411 ms |
14852 KB |
Output is correct |
27 |
Correct |
168 ms |
8692 KB |
Output is correct |
28 |
Correct |
161 ms |
8452 KB |
Output is correct |
29 |
Execution timed out |
7070 ms |
6764 KB |
Time limit exceeded |
30 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
0 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
0 ms |
4444 KB |
Output is correct |
17 |
Correct |
9 ms |
6488 KB |
Output is correct |
18 |
Correct |
128 ms |
6492 KB |
Output is correct |
19 |
Correct |
398 ms |
12624 KB |
Output is correct |
20 |
Correct |
1 ms |
4440 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
515 ms |
16888 KB |
Output is correct |
23 |
Correct |
516 ms |
16892 KB |
Output is correct |
24 |
Correct |
13 ms |
6492 KB |
Output is correct |
25 |
Correct |
531 ms |
17140 KB |
Output is correct |
26 |
Correct |
411 ms |
14852 KB |
Output is correct |
27 |
Correct |
168 ms |
8692 KB |
Output is correct |
28 |
Correct |
161 ms |
8452 KB |
Output is correct |
29 |
Execution timed out |
7070 ms |
6764 KB |
Time limit exceeded |
30 |
Halted |
0 ms |
0 KB |
- |