【Tsinsen】A1280. 最长双回文串
http://www.tsinsen.com/A1280###
题目分析:记录一个点向后和向前的最长回文串,然后就是max(Llen[i]+Rlen[i+1])了。
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std ;
typedef long long LL ;
#define rep( i , a , b ) for ( int i = ( a ) ; i < ( b ) ; ++ i )
#define For( i , a , b ) for ( int i = ( a ) ; i <= ( b ) ; ++ i )
#define rev( i , a , b ) for ( int i = ( a ) ; i >= ( b ) ; -- i )
#define clr( a , x ) memset ( a , x , sizeof a )
const int MAXN = 100005 ;
const int N = 26 ;
struct Palindromic_Tree {
int next[MAXN][N] ;
int fail[MAXN] ;
int cnt[MAXN] ;
int len[MAXN] ;
int S[MAXN] ;
int last ;
int n ;
int p ;
int newnode ( int l ) {
for ( int i = 0 ; i < N ; ++ i ) next[p][i] = 0 ;
cnt[p] = 0 ;
len[p] = l ;
return p ++ ;
}
void init () {
p = 0 ;
newnode ( 0 ) ;
newnode ( -1 ) ;
last = 0 ;
n = 0 ;
S[n] = -1 ;
fail[0] = 1 ;
}
int get_fail ( int x ) {
while ( S[n - len[x] - 1] != S[n] ) x = fail[x] ;
return x ;
}
int add ( int c ) {
c -= 'a' ;
S[++ n] = c ;
int cur = get_fail ( last ) ;
if ( !next[cur][c] ) {
int now = newnode ( len[cur] + 2 ) ;
fail[now] = next[get_fail ( fail[cur] )][c] ;
next[cur][c] = now ;
}
last = next[cur][c] ;
cnt[last] ++ ;
return len[last] ;
}
void count () {
for ( int i = p - 1 ; i >= 0 ; -- i ) cnt[fail[i]] += cnt[i] ;
}
} ;
Palindromic_Tree T ;
int n ;
int len[MAXN] ;
char s[MAXN] ;
void solve () {
int ans = 0 ;
n = strlen ( s ) ;
T.init () ;
for ( int i = n - 1 ; i >= 0 ; -- i ) {
len[i] = T.add ( s[i] ) ;
}
T.init () ;
for ( int i = 0 ; i < n - 1 ; ++ i ) {
ans = max ( ans , T.add ( s[i] ) + len[i + 1] ) ;
}
printf ( "%d\n" , ans ) ;
}
int main () {
while ( ~scanf ( "%s" , s ) ) solve () ;
return 0 ;
}
【Tsinsen】A1280. 最长双回文串的更多相关文章
- 青橙 A1280. 最长双回文串
A1280. 最长双回文串 时间限制:2.0s 内存限制:512.0MB 总提交次数: AC次数: 平均分: 将本题分享到: 查看未格式化的试题 提交 试题讨 ...
- A1280. 最长双回文串
学习了回文树,地址:http://blog.csdn.net/u013368721/article/details/42100363: 这个题就是正这反着加一遍就好,一开始我想的是枚举每个位置,然后一 ...
- Tsinsen 最长双回文串
求最长双回文串,正反建回文树求最大. 题目链接:http://www.tsinsen.com/ViewGProblem.page?gpid=A1280 By:大奕哥 #include<bits/ ...
- BZOJ 2565: 最长双回文串 [Manacher]
2565: 最长双回文串 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1842 Solved: 935[Submit][Status][Discu ...
- 【BZOJ2565】最长双回文串(回文树)
[BZOJ2565]最长双回文串(回文树) 题面 BZOJ 题解 枚举断点\(i\) 显然的,我们要求的就是以\(i\)结尾的最长回文后缀的长度 再加上以\(i+1\)开头的最长回文前缀的长度 至于最 ...
- BZOJ.2565.[国家集训队]最长双回文串(Manacher/回文树)
BZOJ 洛谷 求给定串的最长双回文串. \(n\leq10^5\). Manacher: 记\(R_i\)表示以\(i\)位置为结尾的最长回文串长度,\(L_i\)表示以\(i\)开头的最长回文串长 ...
- P4555 [国家集训队]最长双回文串
P4555 [国家集训队]最长双回文串 manacher 用manacher在处理时顺便把以某点开头/结尾的最长回文串的长度也处理掉. 然后枚举. #include<iostream> # ...
- bzoj 2565: 最长双回文串 manacher算法
2565: 最长双回文串 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/problem. ...
- 【BZOJ2565】最长双回文串 Manacher
[BZOJ2565]最长双回文串 Description 顺序和逆序读起来完全一样的串叫做回文串.比如acbca是回文串,而abc不是(abc的顺序为“abc”,逆序为“cba”,不相同).输入长度为 ...
随机推荐
- Linux安装配置Redis CentOS 7 下安装Redis
Redis是一个高性能的,开源key-value型数据库.是构建高性能,可扩展的Web应用的完美解决方案,可以内存存储亦可持久化存储.因为要使用跨进程,跨服务级别的数据缓存,在对比多个方案后,决定使用 ...
- Android中Looper的quit方法和quitSafely方法
Looper是通过调用loop方法驱动着消息循环的进行: 从MessageQueue中堵塞式地取出一个消息.然后让Handler处理该消息,周而复始.loop方法是个死循环方法. 那怎样终止消息循环呢 ...
- Linux主要命令
pwd 查看当前路径 cd .. 表示后一级目录级 cd . 表示当前目录 cd ../.. 后退两级 cd 表示进入当前家目录 date 返回当前的一个具体时间 -s 修改 ...
- 嵌入式开发之davinci--- 8168 question about capture PAL on 8168
http://e2e.ti.com/support/dsp/davinci_digital_media_processors/f/717/t/340483.aspx?pi199607=2
- Release Candidate
RC_百度百科 https://baike.baidu.com/item/RC/7311964?fr=aladdin RC=Release Candidate,含义是"发布候选版" ...
- RubyMine安装、破解
经常安装东西,这是我安装过最快的ide破解版. 下载地址: http://www.jetbrains.com/ruby/download/index.html 破解序列号: name: rubymin ...
- 新产品为了效果,做的比較炫,用了非常多的图片和JS,所曾经端的性能是非常大的问题,分篇记录前端性能优化的一些小经验。
第一篇:HTTPserver 因tomcat处理静态资源的速度比較慢,所以首先想到的就是把全部静态资源(JS,CSS,image,swf) 提到单独的server,用更加高速的HTTPserver,这 ...
- 20170223 遇到自建表里面相同key值数据不唯一
我怎么发现这个表里 key值相同数据不唯一, 这两条看起来是完全相同的, 其实排序不能能合并已经说明问题.
- [转]GPS NEMA 0183协议
一. NMEA0183标准语句(GPS常用语句) $GPGGA例:$GPGGA,092204.999,4250.5589,S,14718.5084,E,1,04,24.4,19.7,M,,,,0000 ...
- iOS 声明属性关键字的总结
atomic: 原子操作(原子性是指事务的一个完整操作,操作成功就提交,反之就回滚. 原子操作就是指具有原子性的操作)在objective-c 属性设置里面 默认的就是atomic ,意思就是 set ...