Submission #855241

# Submission time Handle Problem Language Result Execution time Memory
855241 2023-10-01T02:22:57 Z willychan Chorus (JOI23_chorus) C++14
0 / 100
0 ms 348 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(ll v){
	for(int i=0;i<=n;i++) dp[i] = {1e18,0};
	dp[0]={0,0};
	for(int i=1;i<=n;i++){
		ll 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 = 1e15;
	while(r-l>1){
		ll mid = l+((r-l)/2);
	//	cout<<l<<" "<<mid<<" "<<r<<"t1\n";
		if(ok(mid)) r = mid;
		else l = mid;
	//	cout<<l<<" "<<mid<<" "<<r<<"t2\n";
	}
	ok(r);
	cout<<dp[n].first-r*dp[n].second<<"\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 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 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 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 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 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 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 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 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 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 Halted 0 ms 0 KB -