QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#246128#4666. Delete And WincryozwqWA 0ms3956kbC++14884b2023-11-10 16:24:122023-11-10 16:24:13

Judging History

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

  • [2023-11-10 16:24:13]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3956kb
  • [2023-11-10 16:24:12]
  • 提交

answer

/* 
*/
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+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);
//	cout<<ans<<endl;
	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']; 
		ans=min(ans,m-now+res);
		if(now==m+1||now==m)break;  
//		cout<<"res"<<res<<" "<<now<<" "<<ans<<endl;
		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: 0ms
memory: 3956kb

input:

pqsrpspqz
pqrpqz

output:

0

result:

wrong answer 1st numbers differ - expected: '2', found: '0'