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. 使用httpModules做一些事

    httpmodules是http管道处理程序 可以重写接口进行一些在请求到达api接口前做全局处理 这是一个过滤关键词的例子 using System; using System.Collection ...

  2. oracle 复杂的查找用法

    [第一题]: 找到员工表中工资最高的前三名,要求按如下格式输出(第一步部分):以及oracle查询结果指定分页显示的方法(第二部分). ——涉及Top-N分析问题. 一般不在子查询中使用order b ...

  3. intellij idea中修改代码生成的模板

    File -- Settings -- Editor -- Code Style -- File and Code Templates 主要是修改了注释 /** * ${DESCRIPTION} * ...

  4. 点滴积累【C#】---操作文件

    操作文件 写入文件效果: 写入文件代码: private void 保存ToolStripMenuItem_Click(object sender, EventArgs e) { try { File ...

  5. swift -变量的定义与使用

    使⽤用let来声明常量,使⽤用var来声明变量. ⼀一个常量的值在编译时并不须要获取,可是你仅仅能为它赋值⼀一次.也就是说你能够⽤用常量来表⽰示这样⼀一个值:你仅仅须要决定⼀一次,可是须要使⽤用非常多 ...

  6. Atitit.获取主板与bios序列号获取硬件设备信息  Wmi wmic 的作用

    Atitit.获取主板与bios序列号获取硬件设备信息  Wmi wmic 的作用 1 获取硬件核心基础核心基础Wmi1 2 其他资料2 3 Wmic WMI 命令行接口2 4 Atitit.获取主板 ...

  7. Registers

    https://github.com/JesusFreke/smali/wiki/Registers Introduction In dalvik's bytecode, registers are ...

  8. IOS使用Charts

    近期项目中要做图表功能,为了降低开发量採用的是H5+ECharts来做.这里说一下IOS中怎样使用ECharts以及遇到的问题. 网络模块化单文件引入 <!DOCTYPE html> &l ...

  9. 使用 xlue 实现 tips

    经常遇到如下的需求 鼠标hover到目标对象一定时间后,弹出tips或者窗口; 鼠标离开目标对象一定时间后,隐藏tips或者窗口; 鼠标从目标对象移动到弹出的窗口上,这种状况下不隐藏窗口; 考虑到这种 ...

  10. phoneGap 3.5 eclipise 模拟器调试

    最近想搞phoneGap开发,可是一看 http://www.phonegapcn.com/ phoneGap中文网 FUCK .phoneGap 还在1.0.0 里混呢.现在phoneGap 3.5 ...