QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#246812 | #4666. Delete And Win | SunsetLake | WA | 0ms | 3596kb | C++14 | 894b | 2023-11-11 09:58:51 | 2023-11-11 09:58:52 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
char s[100005],t[100005];
int n,m,ans=1e9,cnt;
int nxt[100005],lst[30];
int main(){
cin>>(s+1)>>(t+1);
n=strlen(s+1);m=strlen(t+1);
for(int i=0;i<26;++i)lst[i]=m+1;
for(int i=0;i<=m+1;++i)nxt[i]=m+1;
for(int i=m;i>=1;--i){
for(int j=t[i]-'a'-1;j>=0;--j)nxt[i]=min(nxt[i],lst[j]);
lst[t[i]-'a']=i;
}
// cout<<nxt[5]<<endl;
// for(int i=1;i<=m;++i)cout<<nxt[i]<<" ";puts("");
int now=1;
for(int i=1;i<=n;++i){
while(t[now]>s[i]&&now<=m)now++,cnt++;
if(t[now]<s[i])return cout<<min(ans,cnt),0;
if(t[now]==s[i]){
ans=min(ans,cnt+nxt[now]-now);
}
now++;
}
cout<<ans;
return 0;
}
/*
ahhhhhhhhhhhhhhflowerletterishuahua
heisanoierinhighschoolaffiliatedtorenminuniversityofchina
aacbbbbaaaaaaaaaba
db
whqwillsingatninepm
dajiabujianbusan
hyddakioi
whywillaknoi
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3596kb
input:
pqsrpspqz pqrpqz
output:
0
result:
wrong answer 1st numbers differ - expected: '2', found: '0'