#include<iostream>
#include<vector>
using namespace std;
#define forn(i, n) for(int i=0; i<(int)n; ++i)
#define dforn(i, n) for(int i=0; i<(int)n; ++i)
#define forsn(i, s, n) for(int i=s; i<(int)n; ++i)
#define PB push_back
const int MAXN=5010, INF=1e7;
int n, K, pos[MAXN], cost[MAXN][MAXN], dp[MAXN][MAXN];
char str[MAXN];
vector<bool> imp;
int main(){
scanf("%d %d", &n, &K);
scanf("%s", str);
forn(i, n){
int cnA=0, cnB=0, cn=0;
forn(j, 2*n){
if(str[j]=='A'){
cnA++;
if(cnA>i) imp.PB(0);
}
else{
cnB++;
if(cnB>i) imp.PB(1);
}
}
forn(j, 2*(n-i)) if(!imp[j]) pos[cn++]=j;
forsn(j, 1, cn+1) forn(k, j) cost[i][j]+=pos[k]-k;
imp.clear();
}
forn(i, n) dp[0][i]=INF;
forsn(i, 1, K+1) dp[i][n]=INF;
forsn(i, 1, K+1) dforn(j, n){
dp[i][j]=INF;
forsn(k, 1, n-j+1) dp[i][j]=min(dp[i][j], dp[i-1][j+k] + cost[j][k]);
}
printf("%d\n", dp[K][0]);
}
Compilation message
chorus.cpp: In function 'int main()':
chorus.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
15 | scanf("%d %d", &n, &K);
| ~~~~~^~~~~~~~~~~~~~~~~
chorus.cpp:16:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
16 | scanf("%s", str);
| ~~~~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
304 KB |
Output is correct |
4 |
Correct |
1 ms |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
212 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 |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
312 KB |
Output is correct |
11 |
Correct |
1 ms |
304 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 |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
304 KB |
Output is correct |
4 |
Correct |
1 ms |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
212 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 |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
312 KB |
Output is correct |
11 |
Correct |
1 ms |
304 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 |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
4 ms |
1364 KB |
Output is correct |
18 |
Correct |
33 ms |
3280 KB |
Output is correct |
19 |
Correct |
61 ms |
4368 KB |
Output is correct |
20 |
Correct |
19 ms |
2740 KB |
Output is correct |
21 |
Correct |
21 ms |
2732 KB |
Output is correct |
22 |
Correct |
94 ms |
5796 KB |
Output is correct |
23 |
Correct |
99 ms |
5736 KB |
Output is correct |
24 |
Correct |
21 ms |
2772 KB |
Output is correct |
25 |
Correct |
91 ms |
5732 KB |
Output is correct |
26 |
Correct |
77 ms |
5200 KB |
Output is correct |
27 |
Correct |
43 ms |
3700 KB |
Output is correct |
28 |
Correct |
42 ms |
3756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
304 KB |
Output is correct |
4 |
Correct |
1 ms |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
212 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 |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
312 KB |
Output is correct |
11 |
Correct |
1 ms |
304 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 |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
4 ms |
1364 KB |
Output is correct |
18 |
Correct |
33 ms |
3280 KB |
Output is correct |
19 |
Correct |
61 ms |
4368 KB |
Output is correct |
20 |
Correct |
19 ms |
2740 KB |
Output is correct |
21 |
Correct |
21 ms |
2732 KB |
Output is correct |
22 |
Correct |
94 ms |
5796 KB |
Output is correct |
23 |
Correct |
99 ms |
5736 KB |
Output is correct |
24 |
Correct |
21 ms |
2772 KB |
Output is correct |
25 |
Correct |
91 ms |
5732 KB |
Output is correct |
26 |
Correct |
77 ms |
5200 KB |
Output is correct |
27 |
Correct |
43 ms |
3700 KB |
Output is correct |
28 |
Correct |
42 ms |
3756 KB |
Output is correct |
29 |
Execution timed out |
7025 ms |
20760 KB |
Time limit exceeded |
30 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
304 KB |
Output is correct |
4 |
Correct |
1 ms |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
212 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 |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
312 KB |
Output is correct |
11 |
Correct |
1 ms |
304 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 |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
4 ms |
1364 KB |
Output is correct |
18 |
Correct |
33 ms |
3280 KB |
Output is correct |
19 |
Correct |
61 ms |
4368 KB |
Output is correct |
20 |
Correct |
19 ms |
2740 KB |
Output is correct |
21 |
Correct |
21 ms |
2732 KB |
Output is correct |
22 |
Correct |
94 ms |
5796 KB |
Output is correct |
23 |
Correct |
99 ms |
5736 KB |
Output is correct |
24 |
Correct |
21 ms |
2772 KB |
Output is correct |
25 |
Correct |
91 ms |
5732 KB |
Output is correct |
26 |
Correct |
77 ms |
5200 KB |
Output is correct |
27 |
Correct |
43 ms |
3700 KB |
Output is correct |
28 |
Correct |
42 ms |
3756 KB |
Output is correct |
29 |
Execution timed out |
7025 ms |
20760 KB |
Time limit exceeded |
30 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
304 KB |
Output is correct |
4 |
Correct |
1 ms |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
212 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 |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
312 KB |
Output is correct |
11 |
Correct |
1 ms |
304 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 |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
4 ms |
1364 KB |
Output is correct |
18 |
Correct |
33 ms |
3280 KB |
Output is correct |
19 |
Correct |
61 ms |
4368 KB |
Output is correct |
20 |
Correct |
19 ms |
2740 KB |
Output is correct |
21 |
Correct |
21 ms |
2732 KB |
Output is correct |
22 |
Correct |
94 ms |
5796 KB |
Output is correct |
23 |
Correct |
99 ms |
5736 KB |
Output is correct |
24 |
Correct |
21 ms |
2772 KB |
Output is correct |
25 |
Correct |
91 ms |
5732 KB |
Output is correct |
26 |
Correct |
77 ms |
5200 KB |
Output is correct |
27 |
Correct |
43 ms |
3700 KB |
Output is correct |
28 |
Correct |
42 ms |
3756 KB |
Output is correct |
29 |
Execution timed out |
7025 ms |
20760 KB |
Time limit exceeded |
30 |
Halted |
0 ms |
0 KB |
- |