QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#735131#5312. Levenshtein Distancetx344WA 2375ms4820kbC++142.1kb2024-11-11 17:39:532024-11-11 17:39:53

Judging History

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

  • [2024-11-11 17:39:53]
  • 评测
  • 测评结果:WA
  • 用时:2375ms
  • 内存:4820kb
  • [2024-11-11 17:39:53]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define Int __int128
#define ld double
#define fi first
#define se second
#define PII pair<int,int>
#define PLI pair<ll,int>
#define PLL pair<ll,ll>
using namespace std;
const int N=1e5+5,M=35,Mod=1e7+19,Base=71;
int n,m,k,f[M][M*2],pw[N],ha[N],hb[N],ans[M];
char a[N],b[N];
void Max(int &x,int y){x=x<y?y:x;}
int ID(char x){return x>='a'&&x<='z'?x-'a':x>='A'&&x<='Z'?x-'A'+26:x-'0'+52;}
void Init()
{
    pw[0]=1;
    for(int i=1;i<N;i++)pw[i]=pw[i-1]*Base%Mod;
    for(int i=1;i<=n;i++)ha[i]=(ha[i-1]*Base+ID(a[i]))%Mod;
    for(int i=1;i<=m;i++)hb[i]=(hb[i-1]*Base+ID(b[i]))%Mod;
}
inline int Get1(int x,int y){return (ha[y]+(Mod-ha[x-1])*pw[y-x+1])%Mod;}
inline int Get2(int x,int y){return (hb[y]+(Mod-hb[x-1])*pw[y-x+1])%Mod;}
int LCP(int x,int y)
{
    int l=1,r=min(n-x,m-y)+1;
    while(l<=r)
    {
        int mid=l+r>>1;
        if(Get1(x,x+mid-1)==Get2(y,y+mid-1))l=mid+1;
        else r=mid-1;
    }
    return r;
}
int main()
{
    #ifndef ONLINE_JUDGE
    freopen(".in","r",stdin);
    freopen(".out","w",stdout);
    #endif

    scanf("%d%s%s",&k,a+1,b+1),n=strlen(a+1),m=strlen(b+1);
    Init();
    for(int i=1;i<=m;i++)
    {
        memset(f,-63,sizeof(f));
        f[0][M]=0;
        for(int x=0;x<k;x++)
        {
            for(int y=M-x;y<=M+x;y++)if(f[x][y]>=0)
            {
                f[x][y]+=LCP(f[x][y]+1,i-1+f[x][y]+y-M+1);
                Max(f[x+1][y],f[x][y]);
                Max(f[x+1][y-1],f[x][y]);
                Max(f[x+1][y+1],f[x][y]);
                if(f[x][y]<n&&i-1+f[x][y]+y-M<m)Max(f[x+1][y],f[x][y]+1);
                if(f[x][y]<n)Max(f[x+1][y-1],f[x][y]+1);
                if(i-1+f[x][y]+y-M<m)Max(f[x+1][y+1],f[x][y]);
            }
        }
        for(int x=0;x<=k;x++)for(int y=M-x;y<=M+x;y++)if(f[x][y]>=0)
        {
            if(x==k)f[x][y]+=LCP(f[x][y]+1,i-1+f[x][y]+y-M+1);
            if(f[x][y]!=n||n+y-M<=0||i-1+n+y-M>m)continue;
            ++ans[x];
        }
    }
    for(int i=0,las=0;i<=k;i++)printf("%d\n",ans[i]-las),las=ans[i];

	fprintf(stderr,"%.15lf\n",(ld)clock()/CLOCKS_PER_SEC);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 4400kb

input:

4
aaa
aabbaab

output:

0
5
15
7
1

result:

ok 5 number(s): "0 5 15 7 1"

Test #2:

score: 0
Accepted
time: 2375ms
memory: 4820kb

input:

30
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

result:

ok 31 numbers

Test #3:

score: -100
Wrong Answer
time: 563ms
memory: 4760kb

input:

30
BBAAABAABBBA
ABBABBBBAABAAAABABBBAABAABBAABAAAAAABAABABBAAAABAAAAABABAABAABBABBAAAABBBBAABBABAAABAABAABBBBBABBABABBBBABBBBAAABBABABBBBAAABBBBAAAABABABABABABABAAABBBBBAABAABAABBAABBBAABBBBBBBABAABAABAABABAABAAABAABBBAABABBABBAAABAAAABABABBABBBAAABBBAAAABBBBABABABAABAABBBBBBBBBAABBBABABBBABAABBABBA...

output:

0
0
0
3
46
3328
131253
452127
440093
258059
238057
227707
130821
125835
121910
118461
115537
112858
110453
108203
105958
103970
101981
100225
98662
97157
95906
94803
93844
92984
92276

result:

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