QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#700302 | #4666. Delete And Win | Day_Tao | TL | 0ms | 0kb | C++14 | 1.4kb | 2024-11-02 12:40:32 | 2024-11-02 12:40:36 |
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