zoukankan      html  css  js  c++  java
  • 【APIO2014】Palindromes

    2014年好像没有回文树, 但是回文树出来之后就变成裸题了

    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <iostream>
    
    #define rep(i, s, t) for(int i = (s), i##E = (t); i <= i##E; ++i)
    #define dec(i, s, t) for(int i = (s), i##E = (t); i >= i##E; --i)
    
    using namespace std;
    
    const int SIGMA = 26;
    const int MX_N = (3e5 + 10) * 2;
    
    char s[MX_N];
    
    namespace PAM {
        int lst, tot;
        int len[MX_N], val[MX_N];
        int fail[MX_N], ch[MX_N][SIGMA];
    
        void init() {
            tot = 1;
            fail[0] = fail[1] = 1;
            len[1] = -1, lst = 0;
        }
    
        void solve() {
            init();
            rep(i, 1, strlen(s + 1)) {
                int x = s[i] - 'a', h = lst, u = 0;
                while(s[i-len[h]-1] != s[i]) h = fail[h];
                if(!ch[h][x]) {
                    len[u=++tot] = len[h] + 2;
                    int v = fail[h];
                    while(s[i-len[v]-1] != s[i]) v = fail[v];
                    fail[u] = ch[v][x], ch[h][x] = u;
                }++val[lst = ch[h][x]];
            }
        }
    }using namespace PAM;
    
    long long count() {
        long long ret = 0;
        dec(i, tot, 2) val[fail[i]] += val[i];
        rep(i, 2, tot) ret = max(ret, (long long)val[i] * len[i]);
        return ret;
    }
    
    int main() {
    #ifndef ONLINE_JUDGE
        freopen("input.in", "r", stdin);
        freopen("res.out", "w", stdout);
    #endif
        scanf("%s", s + 1);
        solve();
        printf("%lld
    ", count());
        return 0;
    }
  • 相关阅读:
    1208PHP基础
    数据库的查询
    1108 函数
    Shell脚本监控Linux某个后台进程,当进程死掉后重新启动服务,以httpd为例
    Windows下安装Zabbix agent
    Zabbix4.0如何监控Windows主机
    yum下载Zabbix4.0失败的解决方法
    TCP的三次握手与四次挥手理解
    MySQL主从复制原理
    Awk
  • 原文地址:https://www.cnblogs.com/pbvrvnq/p/8530140.html
Copyright © 2011-2022 走看看