http://codeforces.com/contest/126/problem/B

#include<bits/stdc++.h>
using namespace std;
const int M = 1e6 + 10 ;
char s[M] ;
int lens ;
bool vis[M] ;
int NEXT[M] ; void get_fail () {
NEXT[0] = -1 ;
for (int i = 1 , at = -1 ; i < lens ; i ++) {
while (at != -1 && s[at+1] != s[i]) at = NEXT[at] ;
NEXT[i] = s[at+1] == s[i] ? ++at : at ;
}
} void solve () {
get_fail () ;
int at = NEXT[lens-1] ;
while (at != -1) {
vis[at] = 1 ;
at = NEXT[at] ;
}
int maxn = -1 ;
for (int i = lens-2 ; i >= 0 ; i --) {
if (vis[NEXT[i]]) {
if (NEXT[i] > maxn) maxn = NEXT[i] ;
}
}
if (maxn == -1) puts ("Just a legend") ;
for (int i = 0 ; i <= maxn ; i ++) printf ("%c" , s[i]) ; puts ("") ;
} int main () {
scanf ("%s" , s) ;
lens = strlen (s) ;
solve () ;
return 0 ;

最新文章

  1. 中国式IT的项目
  2. C++学习笔记23:库
  3. toad 常用快捷键与配置
  4. 配置Python+selenium+firefox自动化测试
  5. apache 做http代理
  6. Delphi ThreadPool 线程池(Delphi2009以上版本适用)
  7. Android实现Filterable通过输入文本框实现联系人自动筛选
  8. qt外部数据传入实现动态的折线图绘制
  9. vsftp FTP服务器外网访问设置
  10. angularJS 系列(三)- 自定义 Service
  11. svn清理失败且乱码 问题解决
  12. iOS 滚动视图的复用问题解决方案
  13. Winfon 页签切换及窗体控件自适应
  14. js this 引起的祸
  15. PrimeNG之TreeTable
  16. php.ini 配置详解
  17. Win10 1803 Spring Creators update Consumer edition的版本记录
  18. yum源仓库搭建
  19. TNS
  20. Dubbox分布式框架

热门文章

  1. Python版本2.7切3.5和3.5切2.7
  2. 第一个JAVA应用
  3. 使用using释放资源
  4. mybatis传入多个参数
  5. java多线程系类:JUC原子类:04之AtomicReference原子类
  6. [MVC]如何删除文章内容中的图片
  7. 百度数据可视化图表套件echart实战
  8. JavaScript定时器原理分析
  9. ASP.NET SessionState 解惑
  10. K-means聚类算法