QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#179419#6338. Chorusmaoyiting0 1ms3736kbC++14674b2023-09-14 21:18:102023-09-14 21:18:11

Judging History

你现在查看的是最新测评结果

  • [2023-09-14 21:18:11]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:3736kb
  • [2023-09-14 21:18:10]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=5e3+5;
int n,k,t,c[N],g[N],ans;
long long f[N];
char s[N];
bool ok(int v){
	fill(f+1,f+1+n,1e18);
	for(int i=1;i<=n;i++){
		int sum=0;
		for(int j=i;j<=n;j++){
			sum+=max(0,c[j]-(i-1));
			auto tmp=make_pair(f[i-1]+sum+v,g[i-1]+1);
			if(tmp<=make_pair(f[j],g[j])) tie(f[j],g[j])=tmp;
		}
	}
	if(g[n]<=k) ans=f[n]-1ll*g[n]*v;
	return g[n]<=k;
}
signed main(){
	scanf("%d%d%s",&n,&k,s+1);
	for(int i=1,b=0;i<=2*n;i++){
		if(s[i]=='A') c[++t]=b;
		else b++;
	}
	int l=0,r=1e9;
	while(l<=r){
		int mid=(l+r)/2;
		if(ok(mid)) r=mid-1;
		else l=mid+1;
	}
	printf("%d\n",ans);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 16
Accepted
time: 1ms
memory: 3736kb

input:

1 1
BA

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: -16
Wrong Answer
time: 1ms
memory: 3628kb

input:

7 5
ABBAAABBABABBA

output:

4

result:

wrong answer 1st numbers differ - expected: '3', found: '4'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

0%