QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#246891#4666. Delete And WinStruct_SecWA 1ms3328kbC++141.1kb2023-11-11 11:32:572023-11-11 11:32:57

Judging History

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

  • [2023-11-11 11:32:57]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3328kb
  • [2023-11-11 11:32:57]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=5e5+5;
int n,m;
int pos=1,cnt,ans,p=1e18;
vector<int>lt[30];
char c[N],s[N];
signed main(){
	cin>>(s+1)>>(c+1);
	n=strlen(c+1),m=strlen(s+1);
	for(int i=n;i>=1;i--){
		for(int j=c[i]-'a'+2;j<=26;j++){
			lt[j].push_back(i);
		}
	}
	ans=n;
	for(int i=1;i<=m;i++){
		int sum=0;
//		cout<<i<<' '<<pos<<' ';
		while(c[pos]>s[i] && pos<=n){
			pos++;
			sum++;
		}
		cnt+=sum;
//		cout<<pos<<' '<<cnt<<endl;
		if(pos>n) break;
		p=i;
		if(c[pos]<s[i]){
			ans=min(ans,cnt);
			break;
		}
		for(int j=1;j<=26;j++){
			while(lt[j].size() && lt[j][lt[j].size()-1]<=pos){
				lt[j].pop_back();
			}
		}
		if(lt[s[i]-'a'+1].size()){
			ans=min(ans,cnt+lt[s[i]-'a'+1][lt[s[i]-'a'+1].size()-1]-pos);
		}
		pos++;
	}
//	cout<<p<<endl;
	if(p<m) ans=min(ans,cnt);
	else{
		if(p!=1e18){
			ans=min(ans,n-m+1);
		}
	}
	cout<<ans;
	return 0;
}
/*
aaaaaaaaaa
haagaacabbbda


ahhhhhhhhhhhhhhflowerletterishuahua
heisanoierinhighschoolaffiliatedtorenminuniversityofchina

whqwillsingatninepm
dajiabujianbusan

*/

详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3328kb

input:

pqsrpspqz
pqrpqz

output:

0

result:

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