QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#245895 | #4666. Delete And Win | Rain | WA | 0ms | 3704kb | C++14 | 781b | 2023-11-10 14:31:40 | 2023-11-10 14:31:41 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+10;
int n,m,ans=1e9,s[N][30];
char a[N],b[N];
int main(){
scanf("%s%s",a+1,b+1);
n=strlen(a+1),m=strlen(b+1);
for(int i=1;i<=m;++i){
for(int j=1;j<=26;++j){
s[i][j]=s[i-1][j]+s[i][j-1]-s[i-1][j-1]+(b[i]-'a'+1==j);
}
}
for(int i=1,j=0,res=0;i<=n&&j<=m&&res<ans;++i){
int l=j+1,r=m,p=m+1;
while(l<=r){
int mid=l+r>>1;
if(s[mid][a[i]-'a']-s[j][a[i]-'a']>0) r=mid-1,p=mid;
else l=mid+1;
}
ans=min(ans,res+p-j-1);
l=j+1,r=p-1;
p=m+1;
while(l<=r){
int mid=l+r>>1;
if(s[mid][a[i]-'a'+1]-s[mid][a[i]-'a']-s[j][a[i]-'a'+1]+s[j][a[i]-'a']>0) p=mid,r=mid-1;
else l=mid+1;
}
res+=p-j-1;
j=p;
}
printf("%d",ans);
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3704kb
input:
pqsrpspqz pqrpqz
output:
0
result:
wrong answer 1st numbers differ - expected: '2', found: '0'