hdu3068 最长回文串 (manacher)

题目点我点我点我


题目大意:中文题不解释


解题思路:马拉车裸模版题


/* ***********************************************
┆  ┏┓   ┏┓ ┆
┆┏┛┻━━━┛┻┓ ┆
┆┃       ┃ ┆
┆┃   ━   ┃ ┆
┆┃ ┳┛ ┗┳ ┃ ┆
┆┃       ┃ ┆
┆┃   ┻   ┃ ┆
┆┗━┓ 马 ┏━┛ ┆
┆  ┃ 勒 ┃  ┆      
┆  ┃ 戈 ┗━━━┓ ┆
┆  ┃ 壁     ┣┓┆
┆  ┃ 的草泥马  ┏┛┆
┆  ┗┓┓┏━┳┓┏┛ ┆
┆   ┃┫┫ ┃┫┫ ┆
┆   ┗┻┛ ┗┻┛ ┆
************************************************ */

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;

#define rep(i,a,b) for (int i=(a),_ed=(b);i<=_ed;i++)
#define per(i,a,b) for (int i=(b),_ed=(a);i>=_ed;i--)
const int inf_int = 2e9;
const long long inf_ll = 2e18;
#define inf_add 0x3f3f3f3f
#define mod 1000000007
#define LL long long
#define ULL unsigned long long
#define MS0(X) memset((X), 0, sizeof((X)))
#define Sd(X) int (X); scanf("%d", &X)
#define Sdd(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define Sddd(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)

const int maxn = 3e5;
char s[maxn],str[maxn];
int len1,len2,p[maxn],ans;

void init()
{
    str[0] = '$';
    str[1] = '#';
    for(int i=0;ii)p[i] = min(p[id*2-i],mx-i);
        else p[i] = 1;
        for(;str[i-p[i]]==str[i+p[i]];p[i]++);
        if(p[i]+i>mx)
        {
            mx = p[i] + i;
            id = i;
        }
    }
}

int main()
{
	//freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	while(~scanf("%s",s))
    {
        len1 = strlen(s);
        init();
        manacher();
        ans = 0;
        for(int i=0;i


你可能感兴趣的:(manacher)