QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#700350#4666. Delete And Winlanos212WA 0ms3780kbC++20957b2024-11-02 12:46:122024-11-02 12:46:16

Judging History

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

  • [2024-11-02 12:46:16]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3780kb
  • [2024-11-02 12:46:12]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

int T,n,m,to[200001][27]; 
string s,t;

int main(){
ios::sync_with_stdio(false),cin.tie(0);

cin>>T;

while (T--){

cin>>s>>t;
n=s.length();
m=t.length();
s=" "+s+" ";
t=" "+t+" ";
int i=1,j=1,tmp=0,mi=1e9,ans=0;
char ch='a'-1;

for (int i=0;i<=n+1;++i) memset(to[i],0,sizeof(to[i]));
for (int i=n;i;--i){
memcpy(to[i],to[i+1],sizeof(to[i]));
to[i][s[i]-97]=i;
}

while (1){
if (j<=m) for (int k=t[j]-97-1;k>=1;--k) if (to[i][k]) mi=min(mi,ans+to[i][k]-i);
if (i<=n && j<=m){
if (s[i]<t[j]) break;
if (s[i]>t[j]){
if (tmp){++ans; break;}
else ++i,++ans;
}
else if (s[i]==t[j]){
if (s[i]<ch) tmp=1;
ch=s[i];
++i,++j;
}
}
else if (i>n && j>m){
++ans; break;
}
else if (i>n){
break;
}
else if (j>m){
if (tmp){++ans; break;}
tmp=n+1;
for (int k=n;k>=i;--k) if (s[k]<t[m]) tmp=k;
ans+=tmp-(i-1); break;
}
}

mi=min(mi,ans);
cout<<mi<<'\n';

}

return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3780kb

input:

pqsrpspqz
pqrpqz

output:


result:

wrong answer Answer contains longer sequence [length = 1], but output contains 0 elements