Codeforces Beta Round #7 D. Palindrome Degree —— 字符串哈希
题目链接:http://codeforces.com/contest/7/problem/D
1 second
256 megabytes
standard input
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.
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 the only number — the sum of the polindrome degrees of all the string's prefixes.
a2A
1
abacaba
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 —— 字符串哈希的更多相关文章
- Codeforces Beta Round #7 D. Palindrome Degree manacher算法+dp
题目链接: http://codeforces.com/problemset/problem/7/D D. Palindrome Degree time limit per test1 secondm ...
- Codeforces Beta Round #7 D. Palindrome Degree hash
D. Palindrome Degree 题目连接: http://www.codeforces.com/contest/7/problem/D Description String s of len ...
- 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 ...
- Codeforces Beta Round #72 (Div. 2 Only)
Codeforces Beta Round #72 (Div. 2 Only) http://codeforces.com/contest/84 A #include<bits/stdc++.h ...
- Codeforces Beta Round #54 (Div. 2)
Codeforces Beta Round #54 (Div. 2) http://codeforces.com/contest/58 A 找子序列 #include<bits/stdc++.h ...
- Codeforces Beta Round #25 (Div. 2 Only)
Codeforces Beta Round #25 (Div. 2 Only) http://codeforces.com/contest/25 A #include<bits/stdc++.h ...
- Codeforces Beta Round #18 (Div. 2 Only)
Codeforces Beta Round #18 (Div. 2 Only) http://codeforces.com/contest/18 A 暴力 #include<bits/stdc+ ...
- Codeforces Beta Round #5 B. Center Alignment 模拟题
B. Center Alignment 题目连接: http://www.codeforces.com/contest/5/problem/B Description Almost every tex ...
- Codeforces Beta Round 84 (Div. 2 Only)
layout: post title: Codeforces Beta Round 84 (Div. 2 Only) author: "luowentaoaa" catalog: ...
随机推荐
- TCP server和client
http://blog.csdn.net/hguisu/article/details/7445768/ 原文:http://www.cnblogs.com/dolphinX/p/3460545.ht ...
- python 常用库, 随时添加中
python只有你想不到的库,只要你能想到,肯定有对应的库 前面*的为标准库,**的是pip里面的,***则是要手动安装的1)python运行时服务* copy: copy模块提供了对复合(compo ...
- javascript --- 多重继承
多重继承就是指,一个子对象中有不止一个父对象的继承模式. 想要实现她,还是非常简单的,而我们只需要延续属性拷贝的继承思路依次扩展对象即可,而对参数中所继承的对象没有限制. function multi ...
- 邁向IT專家成功之路的三十則鐵律 鐵律二十九 IT人富足之道-信仰
天地自然的循環法則,讓每一個人都必須經歷生.老.病.死.喜.怒.哀.樂,然而至始至終無盡的煩惱總是遠多於快樂,因此筆者深信每一個人在一生當中,都必須要有適合自己的正確信仰,他可以在你無法以物質力量來解 ...
- Android Intent调用 Uri的使用几种格式
打开百度 Uri uri = Uri.parse("http://www.baidu.com"); Intent intent =new Intent(Intent.ACTION_ ...
- gulp安装+一个超简单入门小demo
gulp安装參考.gulp安装參考2. 一.NPM npm是node.js的包管理工具.主要功能是管理.更新.搜索.公布node的包. Gulp是通过npm安装的. 所以首先,须要安装node.js. ...
- UVA571 - Jugs(数论)
UVA571 - Jugs(数论) 题目链接 题目大意:给你A和B的水杯.给你三种操作:fill X:把X杯里面加满水.empty X:把X杯中的水清空.pour X Y 把X的水倒入Y中直到一方满或 ...
- navicat for mysql 快捷键(原创)
navicat for mysql 快捷键(原创) 在谷歌,百度上基本搜索不出来这方面的内容,我总结了一下,方便新手,节省一些探索的时间. 1.ctrl+q 打开查询窗口2.ctr ...
- python 中的电子邮箱的操作
通过python 的代码实现对email的操作,包括发送邮件和读取邮件. import poplib import smtplib from email.header import decode_he ...
- VS2012+Win7站点公布具体步骤
VS2012+Win7站点公布详细步骤 本机环境: 本文分三个部分介绍Web项目公布的常规方法,大神级别能够略过,主要是为了方便一些刚開始学习的人. 第一部分:VS2012把项目公布到文件系统. 第二 ...