QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#735097#5312. Levenshtein Distancelittle_pinkpigWA 1ms4752kbC++142.5kb2024-11-11 17:20:442024-11-11 17:20:45

Judging History

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

  • [2024-11-11 17:20:45]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4752kb
  • [2024-11-11 17:20:44]
  • 提交

answer

#include<bits/stdc++.h>
#define MAXK (35)
#define MAXN (100005)
#define ll long long
#define ull unsigned long long
#define db double
#define ldb long double
#define pi pair<int,int>
#define fi first
#define se second
using namespace std;
const int bas=131,lim=100000;
template<typename type>
void read(type &x)
{
    bool f=0;char ch=0;x=0;
    while(ch<'0'||ch>'9'){f|=!(ch^'-');ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
    x=f?-x:x;
}
template<typename type,typename... Args>
void read(type &x,Args &... args)
{
    read(x);
    read(args...);
}
char strs[MAXN],strt[MAXN];
int xlim,n,m;
int f[MAXK][MAXK<<1],buc[MAXK];
ll ans;
ull pw[MAXN],has[2][MAXN];
inline int getx(char ch)
{
    if(ch>='a'&&ch<='z') return ch-'a'+1;
    if(ch>='A'&&ch<='Z') return ch-'A'+27;
    return ch-'0'+53;
}
inline ull gethas(int typ,int l,int r){return has[typ][r]-has[typ][l-1]*pw[r-l+1];}
inline int lcp(int x,int y)
{
    //lcp(S[x,n],T[y,m])
    int l=1,r=min(n-x+1,m-y+1),mid,res=0;
    while(l<=r)
    {
        mid=l+r>>1;
        if(gethas(0,x,x+mid-1)==gethas(1,y,y+mid-1)) l=mid+1,res=mid;
        else r=mid-1;
    }
    return res;
}
void init()
{
    pw[0]=1;
    for(int i=1;i<=lim;i++)  pw[i]=pw[i-1]*bas;
    for(int i=1;i<=n;i++) has[0][i]=has[0][i-1]*bas+getx(strs[i]);
    for(int i=1;i<=m;i++) has[1][i]=has[1][i-1]*bas+getx(strt[i]);
}
inline void cyc(int st)
{
    memset(f,0,sizeof(f));
    for(int i=0;i<=xlim;i++)
    {
        for(int j=-i;j<=i;j++)
        {
            f[i][j+xlim]+=lcp(f[i][j+xlim]+1,f[i][j+xlim]+st+j);
            if(i^xlim)
            {
                f[i+1][j+xlim-1]=max(f[i+1][j+xlim-1],min(f[i][j+xlim]+1,n));
                f[i+1][j+xlim]=max(f[i+1][j+xlim],min(f[i][j+xlim]+1,n));
                f[i+1][j+xlim+1]=max(f[i+1][j+xlim+1],f[i][j+xlim]);
            }
        }
    }
    for(int j=-min(xlim,n-1);j<=min(xlim,m-st-n+1);j++)
    {
        for(int i=0;i<=xlim;i++)
        {
            if(f[i][j+xlim]==n)
            {
                ++buc[i];
                break;
            }
        }
    }
}
int main()
{
#ifndef ONLINE_JUDGE
    freopen(".in","r",stdin);
    freopen(".out","w",stdout);
#endif
    read(xlim);
    scanf("%s",strs+1);n=strlen(strs+1);
    scanf("%s",strt+1);m=strlen(strt+1);
    init();
    for(int st=1;st<=m;++st) cyc(st);
    for(int i=0;i<=xlim;i++) ans+=buc[i];
    printf("%lld",ans);
}

詳細信息

Test #1:

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

input:

4
aaa
aabbaab

output:

28

result:

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