QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#236618#7512. Almost Prefix Concatenationjerry2007WA 8ms32192kbC++142.8kb2023-11-04 09:05:242023-11-04 09:05:24

Judging History

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

  • [2023-11-04 09:05:24]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:32192kb
  • [2023-11-04 09:05:24]
  • 提交

answer

# include <bits/stdc++.h>
# define N 1000005
# define mod1 998244853
# define mod2 1000000009
# define mod 998244353
# define p 31
using namespace std;
int lens,lent;
char s[N],t[N];
struct Hash
{
    long long num1,num2;
    bool operator ==(const Hash x)const
    {
        return num1==x.num1 && num2==x.num2;
    }
    Hash operator *(const long long x)const
    {
        return {num1*x%mod1,num2*x%mod2};
    }
    Hash operator +(const long long x)const
    {
        return {(num1+x)%mod1,(num2+x)%mod2};
    }
    Hash operator -(const long long x)const
    {
        return {(num1-x+mod1)%mod1,(num2-x+mod2)%mod2};
    }
    Hash operator *(const Hash x)const
    {
        return {num1*x.num1%mod1,num2*x.num2%mod2};
    }
    Hash operator +(const Hash x)const
    {
        return {(num1+x.num1)%mod1,(num2+x.num2)%mod2};
    }
    Hash operator -(const Hash x)const
    {
        return {(num1-x.num1+mod1)%mod1,(num2-x.num2+mod2)%mod2};
    }
}h1[N],h2[N];
Hash qpow[N];
Hash get1(int l,int r)
{
    assert(r<=lens);
    return h1[r]-qpow[r-l+1]*h1[l-1];
}
Hash get2(int l,int r)
{
    assert(r<=lent);
    return h2[r]-qpow[r-l+1]*h2[l-1];
}
long long f0[N],f1[N],f2[N];
long long sum0[N],sum1[N],sum2[N];
int main()
{
    qpow[0]={1,1};
    for(int i=1;i<=1000000;i++)
        qpow[i]=qpow[i-1]*p;
    scanf("%s",s+1);
    lens=strlen(s+1);
    scanf("%s",t+1);
    lent=strlen(t+1);
    for(int i=1;i<=lens;i++)
        h1[i]=h1[i-1]*p+s[i];
    for(int i=1;i<=lent;i++)
        h2[i]=h2[i-1]*p+t[i];
    f0[lens+1]=1;
    sum0[lens+1]=1;
    for(int i=lens;i>=1;i--)
    {
        int L=i,R=lens,pos=i-1;
        while(L<=R)
        {
            int mid=L+R>>1;
            if(mid-i+1<=lent && get1(i,mid)==get2(1,mid-i+1))
            {
                pos=mid;
                L=mid+1;
            }
            else
                R=mid-1;
        }
        int nowr;
        if(pos+1>=lens)
            nowr=lens;
        else if(pos-i+1==lent)
            nowr=pos;
        else
        {
            int L=pos+2,R=lens;
            nowr=pos+1;
            while(L<=R)
            {
                int mid=L+R>>1;
                if(mid-i+1<=lent && get1(pos+2,mid)==get2(pos+2-i+1,mid-i+1))
                {
                    nowr=mid;
                    L=mid+1;
                }
                else
                    R=mid-1;
            }
        }
        long long now0=(sum0[i+1]-sum0[nowr+2]+mod)%mod,now1=(sum1[i+1]-sum1[nowr+2]+mod)%mod,now2=(sum2[i+1]-sum2[nowr+2]+mod)%mod;
        f0[i]=now0;
        f1[i]=(now1+now0)%mod;
        f2[i]=(now2+2*now1+now0)%mod;
        sum0[i]=(sum0[i+1]+f0[i])%mod;
        sum1[i]=(sum1[i+1]+f1[i])%mod;
        sum2[i]=(sum2[i+1]+f2[i])%mod;
    }
    cout<<f2[1]<<endl;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 30124kb

input:

ababaab
aba

output:

473

result:

ok 1 number(s): "473"

Test #2:

score: 0
Accepted
time: 8ms
memory: 32084kb

input:

ac
ccpc

output:

5

result:

ok 1 number(s): "5"

Test #3:

score: -100
Wrong Answer
time: 4ms
memory: 32192kb

input:

qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq...

output:

495807373

result:

wrong answer 1st numbers differ - expected: '75038697', found: '495807373'