QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#246812#4666. Delete And WinSunsetLakeWA 0ms3596kbC++14894b2023-11-11 09:58:512023-11-11 09:58:52

Judging History

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

  • [2023-11-11 09:58:52]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3596kb
  • [2023-11-11 09:58:51]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;
char s[100005],t[100005];
int n,m,ans=1e9,cnt; 
int nxt[100005],lst[30];
int main(){
	cin>>(s+1)>>(t+1);
	n=strlen(s+1);m=strlen(t+1);
	for(int i=0;i<26;++i)lst[i]=m+1;
	for(int i=0;i<=m+1;++i)nxt[i]=m+1;
	for(int i=m;i>=1;--i){
		for(int j=t[i]-'a'-1;j>=0;--j)nxt[i]=min(nxt[i],lst[j]);
		lst[t[i]-'a']=i;
	}
//	cout<<nxt[5]<<endl;
//	for(int i=1;i<=m;++i)cout<<nxt[i]<<" ";puts("");
	int now=1;
	for(int i=1;i<=n;++i){
		while(t[now]>s[i]&&now<=m)now++,cnt++;
		if(t[now]<s[i])return cout<<min(ans,cnt),0;
		if(t[now]==s[i]){
			ans=min(ans,cnt+nxt[now]-now);
		}
		now++;
	}
	cout<<ans;
	return 0;
}
/*
ahhhhhhhhhhhhhhflowerletterishuahua
heisanoierinhighschoolaffiliatedtorenminuniversityofchina

aacbbbbaaaaaaaaaba
db

whqwillsingatninepm
dajiabujianbusan

hyddakioi
whywillaknoi
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3596kb

input:

pqsrpspqz
pqrpqz

output:

0

result:

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