比赛 |
NOIP模拟赛by mzx Day2 |
评测结果 |
AAAAAAAAAA |
题目名称 |
拯救紫萱学姐 |
最终得分 |
100 |
用户昵称 |
chad |
运行时间 |
1.231 s |
代码语言 |
C++ |
内存使用 |
60.35 MiB |
提交时间 |
2016-10-20 21:38:08 |
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<ctime>
#include<cmath>
#include<queue>
using namespace std;
#define FILE "savemzx"
#define pii pair<long long,long long>
#define LL long long
#define up(i,j,n) for(int i=j;i<=n;i++)
#define down(i,n,j) for(int i=n;i>=j;i--)
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)<(y)?(x):(y))
#define abs(x) ((x)<0?(-(x)):(x))
template<typename T>inline bool chkmax(T &a,T b){return a<b?a=b,true : false;}
template<typename T>inline bool chkmin(T &a,T b){return a>b?a=b,true : false;}
int read(){
int x=0;char ch=getchar();bool flag=0;
while(ch<'0'||ch>'9'){if(ch=='-')flag=1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return flag?-x:x;
}
namespace OI{
const int maxn=1010000;
const LL inf=10000000000000000LL;
char s[maxn];
int next[maxn],n;
bool vis[maxn];
inline LL squ(int x){return (LL)x*x;}
struct node{
int y,next;
LL v;
}e[maxn<<1];
int linkk[maxn],len=0;
void insert(int x,int y,LL v){
e[++len].y=y;
e[len].next=linkk[x];
linkk[x]=len;
e[len].v=v;
}
LL w[maxn],maxx[maxn],maxx2[maxn],child[maxn];
int fa[maxn];
LL ans=0;
void dfs(int x){
for(int i=linkk[x];i;i=e[i].next){
if(e[i].y==fa[x])continue;
fa[e[i].y]=x;
dfs(e[i].y);
chkmax(ans,e[i].v);
w[e[i].y]+=e[i].v;
if(w[e[i].y]>maxx[x])maxx2[x]=maxx[x],maxx[x]=w[e[i].y];
else if(w[e[i].y]>maxx2[x])maxx2[x]=w[e[i].y];
}
chkmax(ans,maxx[x]+maxx2[x]);
w[x]=maxx[x];
}
void slove(){
scanf("%s",s+1);n=strlen(s+1);
int j=0;next[1]=0;
insert(1,0,1);insert(0,1,1);
for(int i=2;i<=n;i++){
while(s[i]!=s[j+1]&&j)j=next[j];
if(s[i]==s[j+1])j++;
next[i]=j;
insert(j,i,squ(j-i));
insert(i,j,squ(i-j));
}
dfs(0);
printf("%lld\n",ans);
return;
}
}
int main(){
freopen(FILE".in","r",stdin);
freopen(FILE".out","w",stdout);
using namespace OI;
slove();
return 0;
}