QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#245891#4666. Delete And WincryozwqWA 1ms3616kbC++14782b2023-11-10 14:27:002023-11-10 14:27:00

Judging History

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

  • [2023-11-10 14:27:00]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3616kb
  • [2023-11-10 14:27:00]
  • 提交

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'