QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#245911#4666. Delete And WinSelnevWA 1ms3532kbC++14640b2023-11-10 14:34:562023-11-10 14:34:56

Judging History

你现在查看的是最新测评结果

  • [2023-11-10 14:34:56]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3532kb
  • [2023-11-10 14:34:56]
  • 提交

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'