题目链接:http://codeforces.com/contest/7/problem/D

D. Palindrome Degree
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

String s of length n is
called k-palindrome, if it is a palindrome itself, and its prefix and suffix of length  are (k - 1)-palindromes.
By definition, any string (even empty) is 0-palindrome.

Let's call the palindrome degree of string s such a maximum number k,
for which s is k-palindrome.
For example, "abaaba" has degree equals to 3.

You are given a string. Your task is to find the sum of the palindrome degrees of all its prefixes.

Input

The first line of the input data contains a non-empty string, consisting of Latin letters and digits. The length of the string does not exceed 5·106.
The string is case-sensitive.

Output

Output the only number — the sum of the polindrome degrees of all the string's prefixes.

Examples
input
a2A
output
1
input
abacaba
output
6

代码如下:

 #include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const double eps = 1e-;
const int INF = 2e9;
const LL LNF = 9e18;
const int mod = 1e9+;
const int maxn = 5e6+; char s[maxn];
int dp[maxn]; int main()
{
scanf("%s",s+);
int l = , r = , m = ;
for(int i = ; s[i]; i++)
{
l = l*+s[i];
r = r+s[i]*m, m *= ;
if(l==r)
dp[i] = dp[i/]+;
} int ans = ;
for(int i = ; s[i]; i++)
ans += dp[i];
printf("%d\n",ans);
}

Codeforces Beta Round #7 D. Palindrome Degree —— 字符串哈希的更多相关文章

  1. Codeforces Beta Round #7 D. Palindrome Degree manacher算法+dp

    题目链接: http://codeforces.com/problemset/problem/7/D D. Palindrome Degree time limit per test1 secondm ...

  2. Codeforces Beta Round #7 D. Palindrome Degree hash

    D. Palindrome Degree 题目连接: http://www.codeforces.com/contest/7/problem/D Description String s of len ...

  3. Codeforces Beta Round #17 C. Balance (字符串计数 dp)

    C. Balance time limit per test 3 seconds memory limit per test 128 megabytes input standard input ou ...

  4. Codeforces Beta Round #72 (Div. 2 Only)

    Codeforces Beta Round #72 (Div. 2 Only) http://codeforces.com/contest/84 A #include<bits/stdc++.h ...

  5. Codeforces Beta Round #54 (Div. 2)

    Codeforces Beta Round #54 (Div. 2) http://codeforces.com/contest/58 A 找子序列 #include<bits/stdc++.h ...

  6. Codeforces Beta Round #25 (Div. 2 Only)

    Codeforces Beta Round #25 (Div. 2 Only) http://codeforces.com/contest/25 A #include<bits/stdc++.h ...

  7. Codeforces Beta Round #18 (Div. 2 Only)

    Codeforces Beta Round #18 (Div. 2 Only) http://codeforces.com/contest/18 A 暴力 #include<bits/stdc+ ...

  8. Codeforces Beta Round #5 B. Center Alignment 模拟题

    B. Center Alignment 题目连接: http://www.codeforces.com/contest/5/problem/B Description Almost every tex ...

  9. Codeforces Beta Round 84 (Div. 2 Only)

    layout: post title: Codeforces Beta Round 84 (Div. 2 Only) author: "luowentaoaa" catalog: ...

随机推荐

  1. Objective-C 的 API 设计(转)

    英文原文:API Design 转自oschina 参与翻译(14人): 李远超, 魏涛, showme, weizhe72, 周荣冰, crAzyli0n, WangWenjing, throwab ...

  2. Android 学习之路和App开发框架

    学习之路: 1. http://www.stormzhang.com/android/2014/07/07/learn-android-from-rookie/ 框架: 2. https://gith ...

  3. Triangle 三角形——找出三角形中从上至下和最小的路

    Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...

  4. C语言-回溯例3

    排列问题 1.实现排列A(n,m)对指定的正整数m,n(约定1<m<=n),具体实现排列A(n,m).2. 回溯算法设计设置一维数组a,a(i)(i=1,2,…,m)在1—n中取值.首先从 ...

  5. nightwatch testing 注意事项

    coding style 好的測試項目應該盡量不要使用pause 並且要有驗證的機制 .click('input.btn') //.pause(3000) .waitForElementVisible ...

  6. *Android 多线程下载 仿下载助手(改进版)

    首先声明一点: 这里的多线程下载 并非指的 多个线程下载一个 文件.而是 每一个线程 负责一个文件. 真正的多线程 希望后面能给大家带来.  -------------  欢迎 爱学习的小伙伴 加群 ...

  7. UVA 10042 Smith Numbers(数论)

    Smith Numbers Background While skimming his phone directory in 1982, Albert Wilansky, a mathematicia ...

  8. C# 之 集合ArrayList

    .NET Framework提供了用于数据存储和检索的专用类,这些类统称集合. 这些类提供对堆栈.队列.列表和哈希表的支持.大多数集合类实现系统的接口.以下我们主要来讲一下ArrayList.     ...

  9. 何时使用Entity或DTO

    关注公众号: 锅外的大佬 每日推送国外优秀的技术翻译文章,励志帮助国内的开发者更好地成长! JPA和Hibernate允许你在JPQL和Criteria查询中使用DTO和Entity作为映射.当我在我 ...

  10. 【LeetCode with Python】 Sort List

    博客域名:http://www.xnerv.wang 原题页面:https://oj.leetcode.com/problems/sort-list/ 题目类型: 难度评价:★ 本文地址:http:/ ...