QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#245911 | #4666. Delete And Win | Selnev | WA | 1ms | 3532kb | C++14 | 640b | 2023-11-10 14:34:56 | 2023-11-10 14:34:56 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int nxt[100005][26],n,m,ans=1e9,cnt;
char s[100005],t[100005];
int main(){
// freopen("string.in","r",stdin);
// freopen("string.out","w",stdout);
scanf("%s%s",s+1,t+1);
n=strlen(s+1),m=strlen(t+1);
for(int i=0;i<26;i++)nxt[m+1][i]=m;
for(int i=m;i;i--){
for(int j=0;j<26;j++)nxt[i][j]=nxt[i+1][j];
nxt[i][t[i]-'a']=i;
}
int pos=1;
for(int i=1;i<=n;i++){
int go=m;
if(pos>m)break;
for(int j=0;j<s[i]-'a';j++)go=min(go,nxt[pos][j]);
ans=min(ans,cnt+go-pos);
int lp=pos;
pos=nxt[pos][s[i]-'a']+1;
cnt+=pos-lp-1;
}
printf("%d",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3532kb
input:
pqsrpspqz pqrpqz
output:
0
result:
wrong answer 1st numbers differ - expected: '2', found: '0'