QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#397663#5440. P-P-PalindromeDiuWA 271ms80840kbC++141.8kb2024-04-24 15:44:402024-04-24 15:44:44

Judging History

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

  • [2024-04-24 15:44:44]
  • 评测
  • 测评结果:WA
  • 用时:271ms
  • 内存:80840kb
  • [2024-04-24 15:44:40]
  • 提交

answer

// 
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e6+10,bas=131,mod=998244353;
int n;
char s[N];
int hs1[N],hs2[N],t[N],inv[N],ip[N];
map<int,int> mp1[N],mp2;
int qpow(int x,int y=mod-2){
	int m=1;
	for(;y;y>>=1,x=1ll*x*x%mod)if(y&1)m=1ll*m*x%mod;
	return m;
}
int Hs1(int l,int r){
	return (hs1[r]-1ll*hs1[l-1]*t[r-l+1]%mod+mod)%mod;
}
int Hs2(int l,int r){
	return 1ll*(hs2[r]-hs2[l-1]+mod)%mod*inv[l-1]%mod;
}
bool chk(int l,int r){
	return Hs1(l,r)==Hs2(l,r);
}
signed main(){
	scanf("%d",&n);
	t[0]=1;
	for(int i=1;i<N;i++)t[i]=1ll*t[i-1]*bas%mod;
	inv[N-1]=qpow(t[N-1]);
	for(int i=N-2;i>=0;i--)inv[i]=1ll*inv[i+1]*bas%mod;
	for(int i=1;i<N;i++)ip[i]=qpow(1+mod-t[i]);
	ll ans=0;
	for(;n--;){
		scanf("\n%s",s+1);
		int len=strlen(s+1);
		for(int i=1;i<=len;i++)hs1[i]=(1ll*bas*hs1[i-1]+s[i])%mod;
		for(int i=1;i<=len;i++)hs2[i]=(hs2[i-1]+1ll*t[i-1]*s[i])%mod;
		for(int i=1;i<=len;i++){
			int l=0,r=min(i-1,len-i)+1;
			while(l+1<r){
				int mid=l+r>>1;
				if(chk(i-mid,i+mid))l=mid;
				else r=mid;
			}
//			printf("Odd:%d %d\n",i,l);
			for(;l>=0;l--){
				int h=Hs1(i-l,i+l);
				if(mp1[2*l+1][h])break;
//				printf("%d %d\n",i-l,i+l);
				mp1[2*l+1][h]=1;
				int val=1ll*h*ip[2*l+1]%mod;
				int res=++mp2[val];
				ans+=1ll*res*res,ans-=1ll*(res-1)*(res-1);
			}
		}
		for(int i=1;i<len;i++){
			int l=-1,r=min(i-1,len-i-1)+1;
			while(l+1<r){
				int mid=l+r>>1;
				if(chk(i-mid,i+1+mid))l=mid;
				else r=mid;
			}
//			printf("Even:%d %d\n",i,l);
			for(;l>=0;l--){
				int h=Hs1(i-l,i+1+l);
				if(mp1[2*l+2][h])break;
//				printf("%d %d\n",i-l,i+1+l);
				mp1[2*l+2][h]=1;
				int val=1ll*h*ip[2*l+2]%mod;
				int res=++mp2[val];
				ans+=1ll*res*res,ans-=1ll*(res-1)*(res-1);
			}
		}
	}
	printf("%lld\n",ans);
}

詳細信息

Test #1:

score: 100
Accepted
time: 138ms
memory: 65004kb

input:

2
aaaa
aaa

output:

16

result:

ok 1 number(s): "16"

Test #2:

score: 0
Accepted
time: 141ms
memory: 63348kb

input:

3
abaaa
abbbba
bbbaba

output:

28

result:

ok 1 number(s): "28"

Test #3:

score: 0
Accepted
time: 138ms
memory: 66360kb

input:

1
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab

output:

15130

result:

ok 1 number(s): "15130"

Test #4:

score: 0
Accepted
time: 136ms
memory: 64148kb

input:

3
aaaaaaaaaaaaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbbbbbbbbbbb
bababababababaabababababa

output:

1282

result:

ok 1 number(s): "1282"

Test #5:

score: 0
Accepted
time: 190ms
memory: 71628kb

input:

5
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff...

output:

3600000000

result:

ok 1 number(s): "3600000000"

Test #6:

score: 0
Accepted
time: 197ms
memory: 71236kb

input:

5
wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww...

output:

3600000000

result:

ok 1 number(s): "3600000000"

Test #7:

score: -100
Wrong Answer
time: 271ms
memory: 80840kb

input:

3
abbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbab...

output:

133610

result:

wrong answer 1st numbers differ - expected: '133586', found: '133610'