HYSBZ - 3676
模板题。问你一个串里最大的值(回文子串*出现次数)
/* gyt
Live up to every day */
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<cstring>
#include<queue>
#include<set>
#include<string>
#include<map>
#include <time.h>
#define PI acos(-1)
using namespace std;
typedef long long ll;
typedef double db;
const int maxn = 1e6+;
const int sigma=;
const ll mod = ;
const int INF = 0x3f3f3f;
const db eps = 1e-;
struct ptree{
char s[maxn];
int next[maxn][sigma], fail[maxn], cnt[maxn], len[maxn];
int last, n, p;
ll res;
inline int newnode(int l) {
cnt[p]=;
len[p]=l;
return p++;
}
inline void init() {
n=, p=, last=;
memset(next, 0, sizeof(next));
memset(cnt, 0, sizeof(cnt));
memset(len, 0, sizeof(len));
memset(fail, 0, sizeof(fail));
newnode(), newnode(-);
s[n]=-;
fail[]=;
//cout<<n<<" "<<p<<" "<<last<<endl;
}
inline int FL(int x) {
while(s[n-len[x]-]!=s[n]) x=fail[x];
return x;
}
void add(char c) {
c-='a';
s[++n]=c;
int cur=FL(last);
if (!next[cur][c]) {
int now=newnode(len[cur]+);
fail[now]=next[FL(fail[cur])][c];
next[cur][c]=now;
}
last=next[cur][c];
++cnt[last];
}
inline ll countt() {
ll pk=;
for (int i=p-; ~i; --i) {
cnt[fail[i]]+=cnt[i];
pk=max(pk, (ll)cnt[i]*(ll)len[i]);
}
return pk;
}
}p;
char s[maxn];
void solve(){
scanf("%s",s);
int len=strlen(s);
p.init();
for(int i=;i<len;i++)
p.add(s[i]);
printf("%lld\n",p.countt());
}
int main() {
int t = ;
// freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
//scanf("%d", &t);
while(t--)
solve();
return ;
}
HYSBZ - 3676的更多相关文章
- HYSBZ 3676 回文串 (回文树)
3676: [Apio2014]回文串 Time Limit: 20 Sec Memory Limit: 128 MB Submit: 1680 Solved: 707 [Submit][Stat ...
- 回文树练习 Part1
URAL - 1960 Palindromes and Super Abilities 回文树水题,每次插入时统计数量即可. #include<bits/stdc++.h> using ...
- HYSBZ 2038 莫队算法
小Z的袜子(hose) Time Limit:20000MS Memory Limit:265216KB 64bit IO Format:%lld & %llu Submit ...
- BZOJ 3676: [Apio2014]回文串
3676: [Apio2014]回文串 Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 2013 Solved: 863[Submit][Status ...
- HDU 3966 & POJ 3237 & HYSBZ 2243 树链剖分
树链剖分是一个很固定的套路 一般用来解决树上两点之间的路径更改与查询 思想是将一棵树分成不想交的几条链 并且由于dfs的顺序性 给每条链上的点或边标的号必定是连着的 那么每两个点之间的路径都可以拆成几 ...
- HYSBZ 2243
//Accepted 18440 KB 5556 ms /* source:HYSBZ 2243 time :2015.5.29 by :songt */ /*题解: 树链剖分 */ #include ...
- 【BZOJ】3676: [Apio2014]回文串
http://www.lydsy.com/JudgeOnline/problem.php?id=3676 题意:给一个串求回文串×出现次数的最大值.(|S|<=300000) #include ...
- 【BZOJ】【3676】【APIO2014】回文串
回文自动机/Manacher+SA 这道题可以用Manacher找出本质不同的回文串(令max增大的所有回文串),然后再用SA跑出来有多少相同. 还有一种做法就是回文自动机(Orz Hzwer)的裸题 ...
- bzoj 3676: [Apio2014]回文串 回文自动机
3676: [Apio2014]回文串 Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 844 Solved: 331[Submit][Status] ...
随机推荐
- 第四章 栈与队列(c5)栈应用:逆波兰表达式
- c# 关闭和重启.exe程序
Process[] myprocess = Process.GetProcessesByName("a"); if (myprocess.Count() > 0)//判断如果 ...
- f5冗余BIG-IP系统的安装
1.设备服务群集 •一个系列的BIG-Ips彼此互相支持DSC •每一台BIG-IP 自己生成一个Device Object •不同设备的信息 •建立信任证书 •在local device上设置Dev ...
- ubuntu系列-很好用的截图工具shutter
直接在ubuntu软件市场中搜索“shutter”下载即可
- django的request介绍和APIView流程分析和CBV的流程分析
首先get请求的数据都在request.GET中,request.body中没有,因为只有post请求有请求体,request.body中的数据是请求体的数据 首先,我们还是用cbv的方式来讲解 我们 ...
- 面向对象中的property装饰器讲解
面向对象中可以用property来修饰我们的函数,必须下面的例子 class Test(object): def __init__(self,name): self.name = name @prop ...
- RSA加密原理使用方式签名验证
RSA加密原理使用方式签名验证 加密是网络传输中非常重要的一环,它保证了信息的安全性,让他人无法通过抓包来获取通讯的信息也无法通过伪造信息而实现对系统的入侵.其中最为常用的信息传递加密方式就是RS ...
- SQL Merge 语法 单表查询
--项目中需要用到Merg语法,于是去网上查了资料,发现竟然都是多表查询,问题是我只有一张表,于是我纳闷了,后来我灵机一动,就搞定了!--表名:t_login(登录表)--字段:f_userName( ...
- mysql 中 replace into 与 insert into on duplicate key update 的使用和不同点
replace into和insert into on duplicate key update都是为了解决我们平时的一个问题 就是如果数据库中存在了该条记录,就更新记录中的数据,没有,则添加记录. ...
- JFinal Model判断数据库某条记录的属性字段是否包含空值
如果做报表,一条记录中有空值,使用FreeMarker渲染word会报错,并把错误日志输出到Word中.所以需要之前判断下当前记录中属性值是否有空值. package com.huijiasoft.u ...