QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#700302#4666. Delete And WinDay_TaoTL 0ms0kbC++141.4kb2024-11-02 12:40:322024-11-02 12:40:36

Judging History

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

  • [2024-11-02 12:40:36]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-11-02 12:40:32]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ull unsigned long long
#define pii pair<int,int>
#define mp(a,b) make_pair(a,b)
#define fi first
#define se second
#define mid ((l+r)>>1)
#define pc(a) putchar(a)
#define gc() getchar()
#define SZ(a) ((int)a.size())
typedef long long ll;
const int N=2e5+5,M=1e6+5,mod=998244353,INF=INT_MAX;
const ll INFLL = LONG_LONG_MAX;
inline void cmx(int&a,int b){a=max(a,b);}
inline void cmn(int&a,int b){a=min(a,b);}
inline void add(int&a,int b){a+=b;if(a>=mod)a-=mod;}
inline int rd(){
	int x=0,y=1;char c=gc();
	for(;c<'0'||c>'9';c=gc())if(c=='-')y=-1;
	for(;c>='0'&&c<='9';c=gc())x=(x<<1)+(x<<3)+(c^48);
	return x*y;
}char s[N],t[N];int ans,n,m,nxt[N][26],mn=INF;
inline void SOLVE(){
	ans=0,mn=INF;scanf("%s%s",s+1,t+1),n=strlen(s+1),m=strlen(t+1);
	for(int i=0;i<26;i++)nxt[n][i]=INF;
	for(int i=n-1;i>=1;i--){
		for(int j=0;j<26;j++)nxt[i][j]=nxt[i+1][j];
		nxt[i][s[i+1]-'a']=i+1;
	}int j=1;
	for(int i=1;i<=m;i++,j++){
		for(int k=t[i]-'a'-1;~k;k--)cmn(mn,ans+nxt[j][k]-j);
		while(j<=n&&s[j]>t[i])++j,++ans;
		if(s[j]<t[i]){printf("%lld\n",min(ans,mn));return;}
		if(i==m&&j==m){printf("%lld\n",min(ans+1,mn));return;}
		if(i==m){printf("%lld\n",min(mn,ans+n-j+1));}
	}
	return ;
}
signed main(){
//	freopen("string.in","r",stdin);
//	freopen("string.out","w",stdout);
	int T=rd();while(T--) SOLVE();return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

pqsrpspqz
pqrpqz

output:


result: