1297. Palindrome

Time limit: 1.0 second
Memory limit: 64 MB
The “U.S. Robots” HQ has just received a rather alarming anonymous letter. It states that the agent from the competing «Robots Unlimited» has infiltrated into “U.S. Robotics”. «U.S. Robots» security service would have already started an undercover operation to establish the agent’s identity, but, fortunately, the letter describes communication channel the agent uses. He will publish articles containing stolen data to the “Solaris” almanac. Obviously, he will obfuscate the data, so “Robots Unlimited” will have to use a special descrambler (“Robots Unlimited” part number NPRx8086, specifications are kept secret).
Having read the letter, the “U.S. Robots” president recalled having hired the “Robots Unlimited” ex-employee John Pupkin. President knows he can trust John, because John is still angry at being mistreated by “Robots Unlimited”. Unfortunately, he was fired just before his team has finished work on the NPRx8086 design.
So, the president has assigned the task of agent’s message interception to John. At first, John felt rather embarrassed, because revealing the hidden message isn’t any easier than finding a needle in a haystack. However, after he struggled the problem for a while, he remembered that the design of NPRx8086 was still incomplete. “Robots Unlimited” fired John when he was working on a specific module, the text direction detector. Nobody else could finish that module, so the descrambler will choose the text scanning direction at random. To ensure the correct descrambling of the message by NPRx8086, agent must encode the information in such a way that the resulting secret message reads the same both forwards and backwards.
In addition, it is reasonable to assume that the agent will be sending a very long message, so John has simply to find the longest message satisfying the mentioned property.
Your task is to help John Pupkin by writing a program to find the secret message in the text of a given article. As NPRx8086 ignores white spaces and punctuation marks, John will remove them from the text before feeding it into the program.

Input

The input consists of a single line, which contains a string of Latin alphabet letters (no other characters will appear in the string). String length will not exceed 1000 characters.

Output

The longest substring with mentioned property. If there are several such strings you should output the first of them.

Sample

input output
ThesampletextthatcouldbereadedthesameinbothordersArozaupalanalapuazorA
ArozaupalanalapuazorA
Problem Author: Eugene Krokhalev
Problem Source: IX Open Collegiate Programming Contest of the High School Pupils (13.03.2004)
Difficulty: 93    Printable version    Submit solution    Discussion (71)
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
const int N=1e6+;
char s[N],S[N<<];
int l,p[N];
void manacher(){
int mx=-,id=,ans=,pos=;
for(int i=;i<l;i++){
if(id+mx>i) p[i]=min(p[id*-i],id+mx-i);
while(i-p[i]->=&&i+p[i]+<=l&&S[i-p[i]-]==S[i+p[i]+]) p[i]++;
if(id+mx<i+p[i]) id=i,mx=p[i];
if(ans<p[i]) ans=p[i],pos=i;
}
bool f=;
if(S[pos]!='#') pos++;else f=;
pos/=;ans/=;
s[pos+ans+]=;pos-=ans;
if(f) pos++;
puts(s+pos); }
int main(){
while(scanf("%s",s+)==){
int len=strlen(s+);
l=-;
for(int i=;i<=len;i++) S[++l]='#',S[++l]=s[i];
S[++l]='#';
manacher();
}
return ;
}
/*
in:
oUtkzqGlUgWNznyqfXYTPFLgaQrHORMTuKJZtFsmAcWGgMJvtSrRIjElhsCiSGKCFFrHpxdcmQnEZpYsujebwDWhwMbyuDWWHWBJJQlxeCVgokrOuTGbRfVmlionoQiQPGkvMmfNfhohxQvseSoUZOKkXTVxiElofJtujfZPVBWfKBrCrmEyznOUorfwpsYirVQdKwKKWOHoYLDuqqczmqPHBBVpaqldmhmiEdgeqaspGyFbYqdsARnqzcjmjgtndaTpfeFfvVVvooCyOdnelFzDqjzcqRKckRXTnQCWvPRmpnnrRfveyGpWqxcLqEOmotDisqghJtwcouyanxyRAdUvqdLlIvElpleVqEcxBvuYnhTGsoZIfdTdnuCVWOjbfUFtZbaXCIvNaJMsVfhAZfwbHQnmXosLByYxgpCPisNtEuEQsZRZpCTRobllnIYFUKpovYAxhnAUlAamcdkOvZdAHWrGksuYkoOvebZEPGnHZfbvKVgFyrxCtcNzBYpOFgKhSvGPQkEtiRbsQaxAJqlPgnVmTdJXHpmQgVHOCeoSmamjQduUAiRYanAOYgVRmCigUMvFkQSSbNvwTEfozQaucpVIqJHYgtIuxPZZwSySCSkEBnZupGjObKQGQkVCwmtovnjjomQfdieqAxbwpVcEVChnhwuyAagRoqVtDXsThdcWKAFZNAlKkrDwHQFuQwBssJzhKSrotpApDGtUFBngTIZDKMsVVKxTtkKKpdaxfWQrvJelGANVdBnkjATsMMyaLnrOxZnPXGEgBxtr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lEdVfbyfGgbtDVezgjSMLjJmJRFRWYKcBHQpPNihWhBLZurbxhXdNmVwzqyGsoTbucCVxkTkBBviDRJlZVfUnygxmHWbMdDOFHlNZbWfGDJItLDDOCZGkoTprZkAtJgikTHWgEziBNxdspLYliEsOdINixFXBgyNZuSlfwfnIvtFBvYDrRRojBwOiYhjIvHhBquUWSsaScmikxKMsAZsweijSQivoJlUMzyOlwQQIELhdvERYwxxKPoTayBfDxxsCPmWrYXgcfuUNeZvFJoKSlEDQidZdBKZnOGAJaFQwbgKPfCEVBcfSmTgucgKJnkYbbFoXDojHSiUHdkzinrygmyWxtKhlxKvCSwkVApomeausoMTbdmioiFbEgAEYimAzLVLWhITtKEuiIcZEOfGvjOYhjBXlzuKixHyULLkEiWrZuPAjnnmgTwynuFtuydaYhmtBtXuebpBeCKPNibWzycLFiEdZdQkApqFNHlXUkSWkxdLxRBnzTcxXYZzmjjRA out:
vVVv
*/

ural1297. Palindrome的更多相关文章

  1. Ural1297 Palindrome(后缀数组)

        [题目链接] http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=12406 [题意] 求最长回文子串. [思路] 将字符串 ...

  2. 【ural1297】 Palindrome

    http://acm.timus.ru/problem.aspx?space=1&num=1297 (题目链接) 题意 求最长回文子串 Solution 后缀数组论文题 穷举每一位,然后计算以 ...

  3. 1297. Palindrome ural1297(后缀数组)

    1297. Palindrome Time limit: 1.0 secondMemory limit: 64 MB The “U.S. Robots” HQ has just received a ...

  4. URAL1297:Palindrome——题解

    http://acm.timus.ru/problem.aspx?space=1&num=1297 https://vjudge.net/problem/URAL-1297 给定一个字符串,求 ...

  5. 【Ural1297】Palindrome(后缀数组)

    题意:求一个字符串的最长回文子串 n<=1000 思路:这是一道论文题 需要注意的细节: 1.奇偶分类 2.中间的分割符与最后的附加字母都是最小值,但两者不能相同,否则height可能会出现问题 ...

  6. 回文串---Palindrome

    POJ   3974 Description Andy the smart computer science student was attending an algorithms class whe ...

  7. URAL - 1297 Palindrome —— 后缀数组 最长回文子串

    题目链接:https://vjudge.net/problem/URAL-1297 1297. Palindrome Time limit: 1.0 secondMemory limit: 64 MB ...

  8. PALIN - The Next Palindrome 对称的数

    A positive integer is called a palindrome if its representation in the decimal system is the same wh ...

  9. [LeetCode] Longest Palindrome 最长回文串

    Given a string which consists of lowercase or uppercase letters, find the length of the longest pali ...

随机推荐

  1. (八)Oracle学习笔记—— 触发器

    1. 触发器简介 触发器在数据库里以独立的对象存储,类似于过程(procedure)和函数(function),都有声明,执行和异常处理过程的PL/SQL块.它与存储过程和函数不同的是,存储过程与函数 ...

  2. Python 使用 UTF-8 编码(转)

    Python 使用 UTF-8 编码(转) 原文出处:http://blog.chenlb.com/2010/01/python-use-utf-8.html 一般我喜欢用 utf-8 编码,在 py ...

  3. bootstrap 学习笔记 轮播(Carousel)插件

    Bootstrap轮播(carousel)插件是一种灵活的响应式的向站点添加滑块的方式.除些之外,内容也是足够灵活的,可以是图像,内嵌框架,视频或者其他您想要旋转的任何类型的内容. 示例: 下面是不念 ...

  4. 点滴记录:input的value不能放值

     以前我写登录框交互的时候,总是在focus和blur时,把input的value值为空或显示,也一直认为对的没有争议.可是,今天,后台同学告诉我这个不好使了?!我一时没听明白,后来他亲自演示后,我才 ...

  5. Docker运行报Cannot connect to the Docker daemon错误

    核心问题所在:权限不足 操作docker命令提示:Cannot connect to the Docker daemon 请切换管理员权限,root权限,root安装的一般的用户访问会存在此问题.

  6. C#指南,重温基础,展望远方!(4)表达式

    表达式是在操作数和运算符的基础之上构造而成. 表达式的运算符指明了向操作数应用的运算. 运算符的示例包括 +.-.*./ 和 new. 操作数的示例包括文本.字段.局部变量和表达式. 如果表达式包含多 ...

  7. 接收广播BroadcastReceiver

    Broadcast Receiver用于接收并处理广播通知(broadcast announcements).多数的广播是系统发起的,如地域变换.电量不足.来电来信等.程序也可以播放一个广播.程序可以 ...

  8. POJ-1318(list.sort()输出不为字典序,map才是按字典序排列)

    #include<iostream> #include<string> #include<list> #include<map> #include< ...

  9. atitit.验证码识别step2------剪贴板ClipBoard copy image图像 attilax总结

    atitit.验证码识别step2------剪贴板ClipBoard copy image图像 attilax总结 剪贴板(ClipBoard)是内存中的一块区域,是Windows内置的一个非常有用 ...

  10. Git-查看远程分支、本地分支、创建分支

    1.查看本地分支 $ git branch * br-2.1.2.2 master 2.查看远程分支 $ git branch -r origin/HEAD -> origin/master o ...