# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
855244 |
2023-10-01T03:29:03 Z |
willychan |
Chorus (JOI23_chorus) |
C++14 |
|
840 ms |
1372 KB |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include<bits/extc++.h>
//__gnu_pbds
const int N = 5005;
pair<ll,int> dp[N];
int Bpa[N];
int n,K;
bool ok(int v){
for(int i=0;i<=n;i++) dp[i] = {1e18,0};
dp[0]={0,0};
for(int i=1;i<=n;i++){
int cost = 0;
for(int j=1;j<=i;j++){
cost+=max(0,i-Bpa[i-j+1]);
dp[i] = min({dp[i-j].first+cost+v,dp[i-j].second+1},dp[i]);
}
}
//cout<<(dp[n].second<=K)<<" "<<dp[n].first<<" "<<v<<"\n";
return (dp[n].second<=K);
}
int main(){
ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin>>n>>K;
string s;cin>>s;
int pa = 0;
int pb = 0;
for(int i=1;i<=2*n;i++){
if(s[i-1]=='A') pa++;
if(s[i-1]=='B') Bpa[++pb]=pa;
}
ll l = -1;ll r = 1e9;
while(r-l>1){
ll mid = l+((r-l)/2);
if(ok(mid)) r = mid;
else l = mid;
}
ok(r);
//cout<<r<<"\n";
cout<<dp[n].first-r*K<<"\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
468 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 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 |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
468 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 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 |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
2 ms |
348 KB |
Output is correct |
18 |
Correct |
8 ms |
348 KB |
Output is correct |
19 |
Correct |
8 ms |
476 KB |
Output is correct |
20 |
Correct |
8 ms |
348 KB |
Output is correct |
21 |
Correct |
8 ms |
344 KB |
Output is correct |
22 |
Correct |
8 ms |
348 KB |
Output is correct |
23 |
Correct |
8 ms |
460 KB |
Output is correct |
24 |
Correct |
8 ms |
476 KB |
Output is correct |
25 |
Correct |
8 ms |
476 KB |
Output is correct |
26 |
Correct |
8 ms |
476 KB |
Output is correct |
27 |
Correct |
9 ms |
348 KB |
Output is correct |
28 |
Correct |
8 ms |
480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
468 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 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 |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
2 ms |
348 KB |
Output is correct |
18 |
Correct |
8 ms |
348 KB |
Output is correct |
19 |
Correct |
8 ms |
476 KB |
Output is correct |
20 |
Correct |
8 ms |
348 KB |
Output is correct |
21 |
Correct |
8 ms |
344 KB |
Output is correct |
22 |
Correct |
8 ms |
348 KB |
Output is correct |
23 |
Correct |
8 ms |
460 KB |
Output is correct |
24 |
Correct |
8 ms |
476 KB |
Output is correct |
25 |
Correct |
8 ms |
476 KB |
Output is correct |
26 |
Correct |
8 ms |
476 KB |
Output is correct |
27 |
Correct |
9 ms |
348 KB |
Output is correct |
28 |
Correct |
8 ms |
480 KB |
Output is correct |
29 |
Correct |
809 ms |
580 KB |
Output is correct |
30 |
Correct |
809 ms |
760 KB |
Output is correct |
31 |
Correct |
798 ms |
564 KB |
Output is correct |
32 |
Correct |
732 ms |
592 KB |
Output is correct |
33 |
Correct |
732 ms |
600 KB |
Output is correct |
34 |
Correct |
840 ms |
568 KB |
Output is correct |
35 |
Correct |
787 ms |
560 KB |
Output is correct |
36 |
Correct |
808 ms |
344 KB |
Output is correct |
37 |
Correct |
821 ms |
564 KB |
Output is correct |
38 |
Correct |
828 ms |
344 KB |
Output is correct |
39 |
Correct |
823 ms |
344 KB |
Output is correct |
40 |
Correct |
822 ms |
564 KB |
Output is correct |
41 |
Correct |
822 ms |
564 KB |
Output is correct |
42 |
Correct |
816 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
468 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 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 |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
2 ms |
348 KB |
Output is correct |
18 |
Correct |
8 ms |
348 KB |
Output is correct |
19 |
Correct |
8 ms |
476 KB |
Output is correct |
20 |
Correct |
8 ms |
348 KB |
Output is correct |
21 |
Correct |
8 ms |
344 KB |
Output is correct |
22 |
Correct |
8 ms |
348 KB |
Output is correct |
23 |
Correct |
8 ms |
460 KB |
Output is correct |
24 |
Correct |
8 ms |
476 KB |
Output is correct |
25 |
Correct |
8 ms |
476 KB |
Output is correct |
26 |
Correct |
8 ms |
476 KB |
Output is correct |
27 |
Correct |
9 ms |
348 KB |
Output is correct |
28 |
Correct |
8 ms |
480 KB |
Output is correct |
29 |
Correct |
809 ms |
580 KB |
Output is correct |
30 |
Correct |
809 ms |
760 KB |
Output is correct |
31 |
Correct |
798 ms |
564 KB |
Output is correct |
32 |
Correct |
732 ms |
592 KB |
Output is correct |
33 |
Correct |
732 ms |
600 KB |
Output is correct |
34 |
Correct |
840 ms |
568 KB |
Output is correct |
35 |
Correct |
787 ms |
560 KB |
Output is correct |
36 |
Correct |
808 ms |
344 KB |
Output is correct |
37 |
Correct |
821 ms |
564 KB |
Output is correct |
38 |
Correct |
828 ms |
344 KB |
Output is correct |
39 |
Correct |
823 ms |
344 KB |
Output is correct |
40 |
Correct |
822 ms |
564 KB |
Output is correct |
41 |
Correct |
822 ms |
564 KB |
Output is correct |
42 |
Correct |
816 ms |
600 KB |
Output is correct |
43 |
Runtime error |
2 ms |
1372 KB |
Execution killed with signal 11 |
44 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
468 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 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 |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
2 ms |
348 KB |
Output is correct |
18 |
Correct |
8 ms |
348 KB |
Output is correct |
19 |
Correct |
8 ms |
476 KB |
Output is correct |
20 |
Correct |
8 ms |
348 KB |
Output is correct |
21 |
Correct |
8 ms |
344 KB |
Output is correct |
22 |
Correct |
8 ms |
348 KB |
Output is correct |
23 |
Correct |
8 ms |
460 KB |
Output is correct |
24 |
Correct |
8 ms |
476 KB |
Output is correct |
25 |
Correct |
8 ms |
476 KB |
Output is correct |
26 |
Correct |
8 ms |
476 KB |
Output is correct |
27 |
Correct |
9 ms |
348 KB |
Output is correct |
28 |
Correct |
8 ms |
480 KB |
Output is correct |
29 |
Correct |
809 ms |
580 KB |
Output is correct |
30 |
Correct |
809 ms |
760 KB |
Output is correct |
31 |
Correct |
798 ms |
564 KB |
Output is correct |
32 |
Correct |
732 ms |
592 KB |
Output is correct |
33 |
Correct |
732 ms |
600 KB |
Output is correct |
34 |
Correct |
840 ms |
568 KB |
Output is correct |
35 |
Correct |
787 ms |
560 KB |
Output is correct |
36 |
Correct |
808 ms |
344 KB |
Output is correct |
37 |
Correct |
821 ms |
564 KB |
Output is correct |
38 |
Correct |
828 ms |
344 KB |
Output is correct |
39 |
Correct |
823 ms |
344 KB |
Output is correct |
40 |
Correct |
822 ms |
564 KB |
Output is correct |
41 |
Correct |
822 ms |
564 KB |
Output is correct |
42 |
Correct |
816 ms |
600 KB |
Output is correct |
43 |
Runtime error |
2 ms |
1372 KB |
Execution killed with signal 11 |
44 |
Halted |
0 ms |
0 KB |
- |