# 最长回文

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 31611    Accepted Submission(s): 11618

Problem Description

Input

Output

Sample Input

aaaa

abab

Sample Output

4

3

```#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;
//最长回文，Manacher算法
char s[211000],c[111000];//注意S数组的大小至少要开C数组的两倍
int p[211000];//P可以理解为回文字符串的半径

void init()//初始化S数组
{
int i,j;
s[0]=‘@‘;
for(i=0;c[i]!=0;i++)
{
s[2*i+1]=‘#‘;
s[2*i+2]=c[i];
}
s[2*i+1]=‘#‘;
s[2*i+2]=0;
}
int manacher()
{
int id=0,mx=0,i;
for(i=1;s[i]!=0;i++)
{
if(mx>i)
p[i]=min(p[2*id-i],mx-i);
else
p[i]=1;
//p[i]=mx>i?min(p[2*id-i],mx-i):1;
while(s[i+p[i]] == s[i-p[i]])
p[i]++;
if(i+p[i]>mx)
{
mx=i+p[i];
id=i;
}
}
mx=0;
for(i=1;s[i]!=0;i++)
{
if(p[i]>mx)
mx=p[i];
}
return mx-1;
}
int main()//用cin\cout 会超时
{
while(~scanf("%s",c))
{
init();
printf("%d\n",manacher());
}
return 0;
}```

## Longest Substring Without Repeating Characters 字符串中最长的无重复子串长度

Longest Substring Without Repeating Characters Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the lengt