Ural 1960 Palindromes and Super Abilities
Palindromes and Super Abilities
This problem will be judged on Ural. Original ID: 1960
64-bit integer IO format: %lld Java class name: (Any)
Input
Output
Sample Input
aba
Sample Output
1 2 3
Source
#include <bits/stdc++.h>
using namespace std;
const int maxn = ;
struct PalindromicTree{
int fail[maxn],len[maxn],son[maxn][];
int tot,last,n;
char s[maxn];
int newnode(int slen = ){
memset(son[tot],,sizeof son[tot]);
len[tot] = slen;
return tot++;
}
void init(){
n = tot = last = ;
newnode();
newnode(-);
fail[] = fail[] = ;
s[n] = -;
}
int getFail(int x){
while(s[n - len[x] - ] != s[n]) x = fail[x];
return x;
}
void extend(int c){
s[++n] = c;
int cur = getFail(last);
if(!son[cur][c]){
int x = newnode(len[cur] + );
fail[x] = son[getFail(fail[cur])][c];
son[cur][c] = x;
}
last = son[cur][c];
}
}pt;
char str[maxn];
int main(){
while(~scanf("%s",str)){
pt.init();
bool flag = false;
for(int i = ; str[i]; ++i){
pt.extend(str[i] - 'a');
if(flag) putchar(' ');
printf("%d",pt.tot - );
flag = true;
}
putchar('\n');
}
return ;
}
Ural 1960 Palindromes and Super Abilities的更多相关文章
- 回文树(回文自动机) - URAL 1960 Palindromes and Super Abilities
Palindromes and Super Abilities Problem's Link: http://acm.timus.ru/problem.aspx?space=1&num=19 ...
- URAL 2040 Palindromes and Super Abilities 2(回文树)
Palindromes and Super Abilities 2 Time Limit: 1MS Memory Limit: 102400KB 64bit IO Format: %I64d ...
- URAL 2040 Palindromes and Super Abilities 2 (回文自动机)
Palindromes and Super Abilities 2 题目链接: http://acm.hust.edu.cn/vjudge/contest/126823#problem/E Descr ...
- Ural 2040. Palindromes and Super Abilities 2 回文自动机
2040. Palindromes and Super Abilities 2 题目连接: http://acm.timus.ru/problem.aspx?space=1&num=2040 ...
- URAL 2040 Palindromes and Super Abilities 2
Palindromes and Super Abilities 2Time Limit: 500MS Memory Limit: 102400KB 64bit IO Format: %I64d &am ...
- 【URAL】1960. Palindromes and Super Abilities
http://acm.timus.ru/problem.aspx?space=1&num=1960 题意:给一个串s,要求输出所有的s[0]~s[i],i<|s|的回文串数目.(|s|& ...
- 回文树1960. Palindromes and Super Abilities
Bryce1010模板 http://acm.timus.ru/problem.aspx?space=1&num=1960 #include <bits/stdc++.h> usi ...
- URAL1960 Palindromes and Super Abilities
After solving seven problems on Timus Online Judge with a word “palindrome” in the problem name, Mis ...
- Ural2040:Palindromes and Super Abilities(离线&manecher算法)
Dima adds letters s1, …, sn one by one to the end of a word. After each letter, he asks Misha to tel ...
随机推荐
- vmware虚拟机启动centOs黑屏
如图所示 , 我的VM 启动虚拟机之后就变成了上面的样子,一直不动,ping也ping不好,这个时候 : 1. 要么 内存不够了: 2. 要么 网络协议存在问题了: 本地windows环境在管理员的 ...
- Apex 使用和学习
ref doc http://o7planning.org/en/10345/oracle-apex-tutorial-for-beginners (change from web to pdf) ...
- Cannot call sendRedirect()/forward after the response has been committed的问题
问题其实已经很明确了,说明就是不能重定向,因为已经有response了. 然后一检查,是前面已经用servlet的printWriter打印东西了. 所以,重定向前 必须先保证没有任何的输出,包括:1 ...
- 141 Linked List Cycle 环形链表
给定一个链表,判断链表中否有环.补充:你是否可以不用额外空间解决此题?详见:https://leetcode.com/problems/linked-list-cycle/description/ J ...
- [已读]编写可维护的javascript
13年4月份出版,作者是大名鼎鼎的Zakas,他的另两本书<javascript高级程序设计>与<高性能javascript>你一定听过或者读过. 这本书重点讲了编码风格和编码 ...
- [转]自定义ASP.NET MVC JsonResult序列化结果
本文转自:http://blog.163.com/luckcq@yeah/blog/static/17174770720121293437119/ 最近项目中前台页面使用EasyUI的jQuery插件 ...
- Sqlserver调用WebApi
原文地址 http://www.cnblogs.com/lflyq/p/6065160.html sp_configure 'show advanced options', 1;GORECONFI ...
- mvc不登录的情况下无法跳转至其他页面--解决方法之一
在每个控制器里,加以下方法 /// <summary> /// 在调用视图之前拦截非法用户 /// </summary> /// <param name="fi ...
- C#程序A调用程序B的问题
C#程序A调用程序B,如果程序B中存在 string path1 = System.Environment.CurrentDirectory; 程序A中开启B进程的代码为: System.Diagno ...
- 【学习笔记】深入理解js原型和闭包(0)——目录
文章转载:https://www.cnblogs.com/wangfupeng1988/p/4001284.html 说明: 本篇文章一共16篇章,外加两篇后补的和一篇自己后来添加的学习笔记,一共19 ...