QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#245876 | #4666. Delete And Win | Myrrh | WA | 0ms | 3960kb | C++14 | 1.2kb | 2023-11-10 14:19:30 | 2023-11-10 14:19:30 |
Judging History
answer
/*
贪心删有什么问题吗
处理末尾情况。有可能删出来字典序相等
处理中间状态:找到后面第一个比当前对位S字典序小的位置,要不然直接删到那里。然后不删了
或者就删到相等位置,然后下一位
例子:
abaa
azxcvbzxcvaa
朴素:
abaa然后删掉末尾a->aba 删9个
加上中间状态:
aaa 删8个
*/
#include <bits/stdc++.h>
using namespace std;
const int MAXN=2e5+50;
int N,M;
char S[MAXN],T[MAXN];
int Pos[MAXN][27];
int main()
{
// freopen("string.in","r",stdin);
// freopen("string.out","w",stdout);
scanf("%s%s",&S[1],&T[1]);
N=strlen(S+1);
M=strlen(T+1);
/*
前i-1位相等,第i位要么相等,要么比当前小
*/
for(int i=0;i<26;i++)
{
Pos[M+1][i]=M+1;
}
for(int i=M;i>=1;i--)
{
for(int j=0;j<26;j++)
Pos[i][j]=Pos[i+1][j];
Pos[i][T[i]-'a']=i;
}
int ans=1e9;
int Now=0;
int j=1;
for(int i=1;i<=N&&j<=M;i++)
{
int Min=M+1;
for(int k=0;k<S[i]-'a';k++)
Min=min(Min,Pos[j][k]);
//cout<<"j:"<<i<<" "<<j<<" "<<Min<<" "<<Pos[j][S[i]-'a']<<endl;
ans=min(ans,Now+Min-j);
Now+=Pos[j][S[i]-'a']-j;
j=Pos[j][S[i]-'a'];
j++;
}
printf("%d",ans);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3960kb
input:
pqsrpspqz pqrpqz
output:
0
result:
wrong answer 1st numbers differ - expected: '2', found: '0'