QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#179419 | #6338. Chorus | maoyiting | 0 | 1ms | 3736kb | C++14 | 674b | 2023-09-14 21:18:10 | 2023-09-14 21:18:11 |
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;
}
詳細信息
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%