QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#764926#7512. Almost Prefix Concatenationucup-team4352#WA 7ms17976kbC++231.6kb2024-11-20 11:12:102024-11-20 11:12:18

Judging History

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

  • [2024-11-20 11:12:18]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:17976kb
  • [2024-11-20 11:12:10]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
using namespace std;
const int p=2000223479,mod=998244353;
const int maxn=1e6+5;
ll ha[maxn],hb[maxn],qp[maxn];
ll dp2[maxn],dp1[maxn],dp0[maxn];
ll sum2[maxn],sum1[maxn],sum0[maxn];
int n,m;
int d[maxn];
inline ll cala(int l,int r){
	if(r<l)return 0;
	ll tmp=(ha[r]-ha[l-1]*qp[r-l+1]%p);
	return tmp>=0?tmp:tmp+p;
}
inline ll calb(int l,int r){
	if(r<l)return 0;
	ll tmp=(hb[r]-hb[l-1]*qp[r-l+1]%p);
	return tmp>=0?tmp:tmp+p;
}
int find(int x,int y){
	if(x>n)return n;
	if(y>m)return x-(y-m);
	int l=x-1,r=min(n,x+(m-y));
	while(l<r){
		int mid=l+r+1>>1;
		if(cala(x,mid)==calb(y,mid-x+y))l=mid;
		else r=mid-1;
	}
	return l;
}
void solve(){
	string s,t;
	cin>>s>>t;
	n=s.length();
	m=t.length();
	s=" "+s;
	t=" "+t;
	for(int i=1;i<=n;i++){
		ha[i]=(ha[i-1]*1373+s[i])%p;
	}
	for(int i=1;i<=m;i++){
		hb[i]=(hb[i-1]*1373+t[i])%p;
	}
	for(int i=1;i<=n;i++){
		int tmp=find(i,1);
		d[i]=find(tmp+2,tmp+2-i+1);
	}
	dp0[0]=1;
	for(int i=1;i<=n;i++){
		sum2[i]=(sum2[i]+dp2[i-1]+sum2[i-1])%mod;
		sum1[i]=(sum1[i]+dp1[i-1]+sum1[i-1])%mod;
		sum0[i]=(sum0[i]+dp0[i-1]+sum0[i-1])%mod;
		sum2[d[i]+1]=(sum2[d[i]+1]-dp2[i-1]+mod)%mod;
		sum1[d[i]+1]=(sum1[d[i]+1]-dp1[i-1]+mod)%mod;
		sum0[d[i]+1]=(sum0[d[i]+1]-dp0[i-1]+mod)%mod;
		dp2[i]=(sum2[i]+2*sum1[i]+sum0[i])%mod;
		dp1[i]=(sum1[i]+sum0[i])%mod;
		dp0[i]=sum0[i];
	}
	cout<<dp2[n]<<"\n";
}
int main(){
	qp[0]=1;
	for(int i=1;i<=1e6;i++)qp[i]=qp[i-1]*1373%p;
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	// cin>>t;
	while(t--)solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 17920kb

input:

ababaab
aba

output:

473

result:

ok 1 number(s): "473"

Test #2:

score: 0
Accepted
time: 5ms
memory: 17976kb

input:

ac
ccpc

output:

5

result:

ok 1 number(s): "5"

Test #3:

score: -100
Wrong Answer
time: 7ms
memory: 17932kb

input:

qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq...

output:

495807373

result:

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