QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#700350 | #4666. Delete And Win | lanos212 | WA | 0ms | 3780kb | C++20 | 957b | 2024-11-02 12:46:12 | 2024-11-02 12:46:16 |
Judging History
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