QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#178644 | #6338. Chorus | kgqy# | 0 | 1ms | 7900kb | C++14 | 1.6kb | 2023-09-14 10:21:30 | 2024-07-04 02:42:57 |
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
inline int read(){
int w=0;char ch=getchar();
while(!isdigit(ch)) ch=getchar();
while(isdigit(ch)) w=w*10+ch-'0',ch=getchar();
return w;
}
int n,m;
char ch[2000005];
int bel[2000005];
queue<int> q;
int ans;
int dp[5005],cnt[5005],w[5005][5005];
int check(int adv){
if(adv<=1)printf("adv %d\n",adv);
for(int i=1;i<=n;i++){
dp[i]=n*n*4;
for(int j=0;j<i;j++){
if(dp[j]+w[j+1][i]+adv<dp[i]) dp[i]=dp[j]+w[j+1][i]+adv,cnt[i]=cnt[j]+1;
}
if(adv<=1)printf("%d %d\n",dp[i],cnt[i]);
}
return cnt[n];
}
main(){
scanf("%d%d",&n,&m);
scanf("%s",ch+1);
for(int i=1,sum=0;i<=n*2;i++){
if(ch[i]=='A'){
if(sum<0){
int fs=i+sum;
ch[fs]='A';
ch[i]='B';
ans-=sum;
}
sum++;
}
else sum--;
}
// printf("ans %d\n",ans);
// for(int i=1;i<=n*2;i++) putchar(ch[i]);puts("");
for(int i=1;i<=n*2;i++){
if(ch[i]=='A') q.push(i);
else bel[i]=q.front(),q.pop();
// printf("%d ",bel[i]);
}
// puts("");
for(int i=1,id=1;i<=n;i++,id++){
while(ch[id]=='B') id++;
// printf("id %d %d\n",i,id);
for(int j=i,jid=id,sumb=0;j<=n;j++,jid++){
while(ch[jid]=='B') sumb+=(bel[jid]>=id),jid++;
w[i][j]=w[i][j-1]+sumb;
// printf("w %d %d %d %d\n",i,j,w[i][j],jid);
}
}
// for(int i=1;i<=n;i++){
// for(int j=i;j<=n;j++){
// printf("%d %d %d\n",i,j,w[i][j]);
// }
// }
int l=0,r=1000000;
while(l<r){
int mid=(l+r)>>1;
if(check(mid)<=m) r=mid;
else l=mid+1;
}
check(l);
// printf("%d\n",l);
printf("%d\n",dp[n]-l*m+ans);
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 7900kb
input:
1 1 BA
output:
adv 1 1 1 adv 0 0 1 adv 0 0 1 1
result:
wrong output format Expected integer, but "adv" found
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%