题意:给你一个长度1e6 的字符串,取一个前缀字串,取一个后缀字串,使得这两个串拼接起来是回文串。输出最长的回文串。
思路:首先for循环,找到第一位置,使得a【i】!= a【n-i-1】。把i位置到n-i-1位置的串作为带匹配串,跑一遍马拉车,求出p数组。然后找到前缀最大回文串和后缀最大回文串,然后输出较大的那个即可。时间复杂度是o(n)。
#include <bits/stdc++.h>
#define pi pair<int,int>
#define rep(i,l,r) for(int i=(l);i<=(r);i++)
#define mk make_pair
#define ll long long
#define pb push_back
const int mod1 = 998244353,mod = 1e9+7;
using namespace std;
const int maxn = 3e6+10;
char s[maxn],str[maxn],a[maxn];
int n,p[maxn],anss,len,len1;
void init()
{
str[0] = '$';
str[1] = '#';
for(int i=0;i<len1;i++)
{
str[2*i + 2] = s[i];
str[2*i + 3] = '#&#