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