QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#239377 | #7512. Almost Prefix Concatenation | Harry27182 | WA | 1ms | 9884kb | C++14 | 1.9kb | 2023-11-04 20:24:40 | 2023-11-04 20:24:40 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int MOD=998244353,mod1=1000000007,mod2=1000000009,N=1000005;
int f[N][3],hs1[N],hs2[N],ht1[N],ht2[N],p1[N],p2[N],n,m;char s[N],t[N];
int query(int *h,int *p,int l,int r,int mod){return (h[r]-1ll*h[l-1]*p[r-l+1]%mod+mod)%mod;}
struct BIT
{
int tr[N];
void change(int x,int v){for(int i=x;i<=n;i+=i&(-i))tr[i]=(tr[i]+v)%MOD;}
int query(int x){int res=0;for(int i=x;i;i-=i&(-i))res=(res+tr[i])%MOD;return res;}
}tr0,tr1,tr2;
int main()
{
cin.tie(0)->sync_with_stdio(0);
cin>>(s+1)>>(t+1);if(n>10)cout<<(t+1)<<'\n';
n=strlen(s+1),m=strlen(t+1);p1[0]=p2[0]=1;
for(int i=1;i<=max(n,m);i++)
{
p1[i]=1ll*p1[i-1]*131%mod1;
p2[i]=1ll*p2[i-1]*137%mod2;
}
for(int i=1;i<=n;i++)
{
hs1[i]=(1ll*131*hs1[i-1]%mod1+s[i])%mod1;
hs2[i]=(1ll*137*hs2[i-1]%mod2+s[i])%mod2;
}
for(int i=1;i<=m;i++)
{
ht1[i]=(1ll*131*ht1[i-1]%mod1+t[i])%mod1;
ht2[i]=(1ll*137*ht2[i-1]%mod2+t[i])%mod2;
}
for(int i=0;i<=n;i++)
{
f[i][0]=(i==0?1:tr0.query(i));f[i][1]=(i==0?0:tr1.query(i));f[i][2]=(i==0?0:tr2.query(i));
int l=1,r=min(m,n-i),len1=0,len2=0;
while(l<=r)
{
int mid=(l+r)>>1;
if(query(hs1,p1,i+1,i+mid,mod1)==query(ht1,p1,1,mid,mod1)
&&query(hs2,p2,i+1,i+mid,mod2)==query(ht2,p2,1,mid,mod2))l=mid+1,len1=mid;
else r=mid-1;
}
l=1;r=min(m-len1-1,n-i-len1-1);
while(l<=r)
{
int mid=(l+r)>>1;
if(query(hs1,p1,i+len1+1+1,i+len1+1+mid,mod1)==query(ht1,p1,len1+1+1,len1+1+mid,mod1)
&&query(hs2,p2,i+len1+1+1,i+len1+1+mid,mod2)==query(ht2,p2,len1+1+1,len1+1+mid,mod2))l=mid+1,len2=mid;
else r=mid-1;
}
int val0=f[i][0],val1=(f[i][1]+f[i][0])%MOD,val2=((f[i][2]+2*f[i][1]%MOD+f[i][0])%MOD+MOD)%MOD;
l=i+1,r=min(min(i+len1+1+len2,i+m),n);
tr0.change(l,val0);tr0.change(r+1,-val0);
tr1.change(l,val1);tr1.change(r+1,-val1);
tr2.change(l,val2);tr2.change(r+1,-val2);
}
cout<<f[n][2]<<'\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 9800kb
input:
ababaab aba
output:
473
result:
ok 1 number(s): "473"
Test #2:
score: 0
Accepted
time: 0ms
memory: 9816kb
input:
ac ccpc
output:
5
result:
ok 1 number(s): "5"
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 9884kb
input:
qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq...
output:
993760024
result:
wrong answer 1st numbers differ - expected: '75038697', found: '993760024'