zoukankan      html  css  js  c++  java
  • BZOJ2342 [Shoi2011]双倍回文 【manacher】

    题目

    这里写图片描述

    输入格式

    输入分为两行,第一行为一个整数,表示字符串的长度,第二行有个连续的小写的英文字符,表示字符串的内容。

    输出格式

    输出文件只有一行,即:输入数据中字符串的最长双倍回文子串的长度,如果双倍回文子串不存在,则输出0。

    输入样例

    16

    ggabaabaabaaball

    输出样例

    12

    提示

    N<=500000

    题解

    manacher找出所有回文串
    枚举总的中心,再向左枚举次中心
    似乎不会T。。还跑得挺快

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #define LL long long int
    #define REP(i,n) for (int i = 1; i <= (n); i++)
    using namespace std;
    const int maxn = 1000005,maxm = 100005,INF = 1000000000;
    char T[maxn],s[maxn];
    int len,n,RL[maxn];
    void manacher(){
        int pos = 0,MR = 0;
        for (int i = 1; i <= n; i++){
            if (MR > i) RL[i] = min(RL[2 * pos - i],MR - i);
            else RL[i] = 1;
            while (s[i + RL[i]] == s[i - RL[i]]) RL[i]++;
            if (i + RL[i] > MR) MR = i + RL[i],pos = i;
        }
    }
    int main(){
        scanf("%d
    ",&len); gets(T + 1); s[0] = '*';
        REP(i,len) s[++n] = '#',s[++n] = T[i];
        manacher();
        int ans = 0;
        for (int i = 1; i <= n; i += 2){
            int l = (i - RL[i] + 1 + i) >> 1; if (l % 2 == 0) l++;
            while (l <= i && l + RL[l] < i) l += 2;
            ans = max(ans,((i - l) / 2) * 4);
        }
        printf("%d
    ",ans);
        return 0;
    }
    
  • 相关阅读:
    java 类的关系
    Oracle lock table
    shell 标准输出重定向
    pygame 安装
    进程检查机制
    oracle pivot unpivot
    qt paintEvent
    centos7.5+Ambari2.7.3部署安装
    Linux机器间配置ssh互信
    普通视图和物化视图的区别
  • 原文地址:https://www.cnblogs.com/Mychael/p/8282717.html
Copyright © 2011-2022 走看看