QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#236859 | #7512. Almost Prefix Concatenation | Evier | WA | 13ms | 26244kb | C++14 | 1.9kb | 2023-11-04 11:07:13 | 2023-11-04 11:07:14 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int mod=998244353,base=13331,m1=1e9+7,m2=1e9+9;
typedef long long ll;
inline int read(){
int x=0;bool f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=0;ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
if(f)return x;
return ~(x-1);
}
char s[1000005],t[1000005];
int n,m;
struct h{
int mod;
ll h1[1000005],h2[1000005],pw[1000005];
void build(int x){
mod=x;
pw[0]=1;
for(int i=1;i<=1e6;i++)pw[i]=pw[i-1]*base%mod;
for(int i=1;i<=n;i++){
h1[i]=(h1[i-1]*base+s[i])%mod;
}
for(int i=1;i<=m;i++){
h2[i]=(h2[i-1]*base+t[i])%mod;
}
}
bool cmp(int l1,int r1,int l2,int r2){
assert(r1-l1+1==r2-l2+1);
return ((h2[r2]-h2[l2-1]*pw[r2-l2+1]%mod+mod)%mod)==((h1[r1]-h1[l1-1]*pw[r1-l1+1]%mod+mod)%mod);
}
}c1,c2;
bool cmp(int l1,int r1,int l2,int r2){
return c1.cmp(l1,r1,l2,r2)&&c2.cmp(l1,r1,l2,r2);
}
struct bit{
ll c[1000005];
inline void add(int x,ll y){
for(;x<=n;x+=x&-x)(c[x]+=y)%=mod;
}
inline ll ask(int x){
ll res=0;
for(;x;x-=x&-x)res+=c[x];
return res%mod;
}
inline void add(int l,int r,ll v){
add(l,v),add(r+1,-v);
}
}t0,t1,t2;
int main(){
scanf("%s",s+1),scanf("%s",t+1);
n=strlen(s+1),m=strlen(t+1);
c1.build(m1),c2.build(m2);
for(int i=0;i<n;i++){
int R=0;
int l=1,r=min(n-i,m),res=0;
while(l<=r){
int mid=l+r>>1;
if(cmp(i+1,i+mid,1,mid))l=mid+1,res=mid;
else r=mid-1;
}
R=res;
if(R<min(n-i,m)){
++R;
l=1,r=min(n-R-i,m-R),res=0;
while(l<=r){
int mid=l+r>>1;
if(cmp(i+R+1,i+R+mid,R+1,R+mid))l=mid+1,res=mid;
else r=mid-1;
}
R+=res;
R=min(R,m);
}
R+=i;
assert(R-i<=m);
int c0=t0.ask(i),c1=t1.ask(i),c2=t2.ask(i);
if(i==0)c0=1;
t0.add(i+1,R,c0),t1.add(i+1,R,c1+c0),t2.add(i+1,R,(c2+2*c1+c0)%mod);
}
cout<<t2.ask(n);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 24060kb
input:
ababaab aba
output:
473
result:
ok 1 number(s): "473"
Test #2:
score: 0
Accepted
time: 13ms
memory: 26244kb
input:
ac ccpc
output:
5
result:
ok 1 number(s): "5"
Test #3:
score: -100
Wrong Answer
time: 13ms
memory: 24296kb
input:
qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq...
output:
342879614
result:
wrong answer 1st numbers differ - expected: '75038697', found: '342879614'