QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#245973 | #4666. Delete And Win | hhhgjy | WA | 0ms | 3612kb | C++14 | 634b | 2023-11-10 14:55:11 | 2023-11-10 14:55:11 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int N,M;char s[100005],t[100005];
int nxt[100005][26],res;
int calc(int p,int ch){return (nxt[p][ch]-p);}
int main(){
scanf("%s%s",t+1,s+1);N=strlen(s+1),M=strlen(t+1);res=N;
for(int i=0;i<26;++i)nxt[N+1][i]=N+1;
for(int i=N;i>=1;--i){
for(int j=0;j<26;++j)nxt[i][j]=nxt[i+1][j];
int now=(s[i]-'a');
for(int j=now+1;j<26;++j)nxt[i][j]=i;
}
res=min(res,calc(1,(int)(t[1]-'a')));int lst=0;
for(int i=1;i<M;++i){
++lst;while(lst<=N&&s[lst]!=t[i])++lst;
if(lst>N)break;res=min(res,lst-i+calc(lst+1,(int)(t[i+1]-'a')));
} cout<<res;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3612kb
input:
pqsrpspqz pqrpqz
output:
0
result:
wrong answer 1st numbers differ - expected: '2', found: '0'