# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
935052 |
2024-02-28T13:13:06 Z |
kim |
Chorus (JOI23_chorus) |
C++17 |
|
1133 ms |
336408 KB |
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define f first
#define s second
const ll inf=1e18;
int a[5005],b[5005],pos[5005];
ll dp[5005][5005],cost[5005][5005];
void play(int l,int r,int optl,int optr,int z){
if(l>r) return;
int mid=l+r>>1;
pair<ll,int> best(inf,0);
for(int i=optl;i<=min(mid,optr);++i){
best=min(best,{dp[z-1][i-1]+cost[i][mid],i});
}
dp[z][mid]=best.f;
play(l,mid-1,optl,best.s,z);
play(mid+1,r,best.s,optr,z);
}
int main(){
ios::sync_with_stdio(false); cin.tie(0);
int n,K; cin>>n>>K;
string s; cin>>s;
for(int i=0,ia=0,ib=0;i<s.length();++i){
if(s[i]=='A') a[++ia]=i;
else b[++ib]=i;
}
for(int i=1,j=1;i<=n;++i){
while(j<=n&&b[j]<a[i]) ++j;
pos[i]=j;
}
for(int i=1;i<=n;++i){
for(int j=i;j<=n;++j){
cost[i][j]=cost[i][j-1]+max(0,pos[j]-i);
}
}
for(int i=1;i<=n;++i) dp[1][i]=cost[1][i];
for(int k=2;k<=K;++k){
play(1,n,1,n,k);
}
cout<<dp[K][n];
return 0;
}
Compilation message
chorus.cpp: In function 'void play(int, int, int, int, int)':
chorus.cpp:14:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
14 | int mid=l+r>>1;
| ~^~
chorus.cpp: In function 'int main()':
chorus.cpp:29:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | for(int i=0,ia=0,ib=0;i<s.length();++i){
| ~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
2 ms |
5212 KB |
Output is correct |
18 |
Correct |
4 ms |
11356 KB |
Output is correct |
19 |
Correct |
7 ms |
17496 KB |
Output is correct |
20 |
Correct |
2 ms |
7260 KB |
Output is correct |
21 |
Correct |
2 ms |
7260 KB |
Output is correct |
22 |
Correct |
8 ms |
27792 KB |
Output is correct |
23 |
Correct |
7 ms |
27740 KB |
Output is correct |
24 |
Correct |
3 ms |
7260 KB |
Output is correct |
25 |
Correct |
7 ms |
27656 KB |
Output is correct |
26 |
Correct |
7 ms |
23644 KB |
Output is correct |
27 |
Correct |
4 ms |
13404 KB |
Output is correct |
28 |
Correct |
4 ms |
13400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
2 ms |
5212 KB |
Output is correct |
18 |
Correct |
4 ms |
11356 KB |
Output is correct |
19 |
Correct |
7 ms |
17496 KB |
Output is correct |
20 |
Correct |
2 ms |
7260 KB |
Output is correct |
21 |
Correct |
2 ms |
7260 KB |
Output is correct |
22 |
Correct |
8 ms |
27792 KB |
Output is correct |
23 |
Correct |
7 ms |
27740 KB |
Output is correct |
24 |
Correct |
3 ms |
7260 KB |
Output is correct |
25 |
Correct |
7 ms |
27656 KB |
Output is correct |
26 |
Correct |
7 ms |
23644 KB |
Output is correct |
27 |
Correct |
4 ms |
13404 KB |
Output is correct |
28 |
Correct |
4 ms |
13400 KB |
Output is correct |
29 |
Correct |
431 ms |
220132 KB |
Output is correct |
30 |
Correct |
1133 ms |
310296 KB |
Output is correct |
31 |
Correct |
302 ms |
182744 KB |
Output is correct |
32 |
Correct |
58 ms |
140624 KB |
Output is correct |
33 |
Correct |
60 ms |
140752 KB |
Output is correct |
34 |
Correct |
841 ms |
336392 KB |
Output is correct |
35 |
Correct |
903 ms |
336408 KB |
Output is correct |
36 |
Correct |
63 ms |
140884 KB |
Output is correct |
37 |
Correct |
305 ms |
180704 KB |
Output is correct |
38 |
Correct |
741 ms |
302676 KB |
Output is correct |
39 |
Correct |
587 ms |
234028 KB |
Output is correct |
40 |
Correct |
334 ms |
207288 KB |
Output is correct |
41 |
Correct |
319 ms |
207184 KB |
Output is correct |
42 |
Correct |
658 ms |
207380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
2 ms |
5212 KB |
Output is correct |
18 |
Correct |
4 ms |
11356 KB |
Output is correct |
19 |
Correct |
7 ms |
17496 KB |
Output is correct |
20 |
Correct |
2 ms |
7260 KB |
Output is correct |
21 |
Correct |
2 ms |
7260 KB |
Output is correct |
22 |
Correct |
8 ms |
27792 KB |
Output is correct |
23 |
Correct |
7 ms |
27740 KB |
Output is correct |
24 |
Correct |
3 ms |
7260 KB |
Output is correct |
25 |
Correct |
7 ms |
27656 KB |
Output is correct |
26 |
Correct |
7 ms |
23644 KB |
Output is correct |
27 |
Correct |
4 ms |
13404 KB |
Output is correct |
28 |
Correct |
4 ms |
13400 KB |
Output is correct |
29 |
Correct |
431 ms |
220132 KB |
Output is correct |
30 |
Correct |
1133 ms |
310296 KB |
Output is correct |
31 |
Correct |
302 ms |
182744 KB |
Output is correct |
32 |
Correct |
58 ms |
140624 KB |
Output is correct |
33 |
Correct |
60 ms |
140752 KB |
Output is correct |
34 |
Correct |
841 ms |
336392 KB |
Output is correct |
35 |
Correct |
903 ms |
336408 KB |
Output is correct |
36 |
Correct |
63 ms |
140884 KB |
Output is correct |
37 |
Correct |
305 ms |
180704 KB |
Output is correct |
38 |
Correct |
741 ms |
302676 KB |
Output is correct |
39 |
Correct |
587 ms |
234028 KB |
Output is correct |
40 |
Correct |
334 ms |
207288 KB |
Output is correct |
41 |
Correct |
319 ms |
207184 KB |
Output is correct |
42 |
Correct |
658 ms |
207380 KB |
Output is correct |
43 |
Runtime error |
9 ms |
1108 KB |
Execution killed with signal 11 |
44 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
2 ms |
5212 KB |
Output is correct |
18 |
Correct |
4 ms |
11356 KB |
Output is correct |
19 |
Correct |
7 ms |
17496 KB |
Output is correct |
20 |
Correct |
2 ms |
7260 KB |
Output is correct |
21 |
Correct |
2 ms |
7260 KB |
Output is correct |
22 |
Correct |
8 ms |
27792 KB |
Output is correct |
23 |
Correct |
7 ms |
27740 KB |
Output is correct |
24 |
Correct |
3 ms |
7260 KB |
Output is correct |
25 |
Correct |
7 ms |
27656 KB |
Output is correct |
26 |
Correct |
7 ms |
23644 KB |
Output is correct |
27 |
Correct |
4 ms |
13404 KB |
Output is correct |
28 |
Correct |
4 ms |
13400 KB |
Output is correct |
29 |
Correct |
431 ms |
220132 KB |
Output is correct |
30 |
Correct |
1133 ms |
310296 KB |
Output is correct |
31 |
Correct |
302 ms |
182744 KB |
Output is correct |
32 |
Correct |
58 ms |
140624 KB |
Output is correct |
33 |
Correct |
60 ms |
140752 KB |
Output is correct |
34 |
Correct |
841 ms |
336392 KB |
Output is correct |
35 |
Correct |
903 ms |
336408 KB |
Output is correct |
36 |
Correct |
63 ms |
140884 KB |
Output is correct |
37 |
Correct |
305 ms |
180704 KB |
Output is correct |
38 |
Correct |
741 ms |
302676 KB |
Output is correct |
39 |
Correct |
587 ms |
234028 KB |
Output is correct |
40 |
Correct |
334 ms |
207288 KB |
Output is correct |
41 |
Correct |
319 ms |
207184 KB |
Output is correct |
42 |
Correct |
658 ms |
207380 KB |
Output is correct |
43 |
Runtime error |
9 ms |
1108 KB |
Execution killed with signal 11 |
44 |
Halted |
0 ms |
0 KB |
- |