cf126b(kmp好题)
2024-08-27 00:25:54
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 ;
}
最新文章
- 中国式IT的项目
- C++学习笔记23:库
- toad 常用快捷键与配置
- 配置Python+selenium+firefox自动化测试
- apache 做http代理
- Delphi ThreadPool 线程池(Delphi2009以上版本适用)
- Android实现Filterable通过输入文本框实现联系人自动筛选
- qt外部数据传入实现动态的折线图绘制
- vsftp FTP服务器外网访问设置
- angularJS 系列(三)- 自定义 Service
- svn清理失败且乱码 问题解决
- iOS 滚动视图的复用问题解决方案
- Winfon 页签切换及窗体控件自适应
- js this 引起的祸
- PrimeNG之TreeTable
- php.ini 配置详解
- Win10 1803 Spring Creators update Consumer edition的版本记录
- yum源仓库搭建
- TNS
- Dubbox分布式框架