一本通题目求调
  • 板块题目总版
  • 楼主zhuyuhao1123
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/12/18 22:11
  • 上次更新2024/12/19 16:04:47
查看原帖
一本通题目求调
526470
zhuyuhao1123楼主2024/12/18 22:11

Link

Seek the Name, Seek the Fame

【题目描述】

给定若干字符串(这些字符串总长 ≤4×105​​ ),在每个字符串中求出所有既是前缀又是后缀的子串长度。

例如:ababcababababcabab,既是前缀又是后缀的:ab,abab,ababcabab,ababcababababcabab。

【输入】 输入若干行,每行一个字符串。

【输出】 对于每个字符串,输出一行,包含若干个递增的整数,表示所有既是前缀又是后缀的子串长度。

【输入样例】

ababcababababcabab
aaaaa

【输出样例】

2 4 9 18
1 2 3 4 5
#include<bits/stdc++.h>
#define N 400001
#define mod 1000000007
using namespace std;
const int b=233;
typedef unsigned long long ull;
ull power[N],sum[N];
char s[N];
ull _(ull x,ull y)
{
	return sum[y]-sum[x-1]*power[y-x+1];
}
int main()
{
	power[0]=1;
	for(int i=1;i<=40000;++i) power[i]=power[i-1]*b;
	while(~scanf("%s",s+1))
	{
		int len=strlen(s+1);
		for(int i=1;i<=len;++i) sum[i]=sum[i-1]*b+s[i];
		for(int i=1;i<=len;++i)
		if(_(1,i)==_(len-i+1,len)) cout<<i<<' ';
		cout<<'\n';
	}
	return 0;
}

60pts求调

6,8,9,10WA

2024/12/18 22:11
加载中...