B. Password
做法有很多,kmp、哈希都可以。wa麻了,调了2个小时才接受自己的做法有问题,固执。 思路: 1.可用哈希手法O(1)判断一个字符串的两端子串是否相同。 2.对字符串的长度进行二分,若这一段(从第二个字符~第n-1的字符)的哈希值等于首部、尾部字符串,则成立。 代码:
#include
#define int long long
#define ios cin.tie(0),cout.tie(0),ios::sync_with_stdio(0);
#define endl '\n'
#define ULL unsigned long long
using namespace std;
const double eps=1e-8;
const int mod=998244353;
const int N=1e6+5;
const int P=131;
ULL p[N],h[N];
char s[N];
int a[N],n,cnt;
int init(char s[])
{
p[0]=1,h[0]=0;
int len=strlen(s+1);
for(int i=1;i(s+1);
n=strlen(s+1);
init(s);
for(int i=1;i
关注
打赏