首页 > 代码库 > CodeForces 7D Palindrome Degree 字符串hash
CodeForces 7D Palindrome Degree 字符串hash
题目链接:点击打开链接
#include<stdio.h> #include<iostream> #include<string.h> #include<set> #include<vector> #include<map> #include<math.h> #include<queue> #include<string> #include<stdlib.h> #include<algorithm> using namespace std; #define N 5001000 #define mod 1000000007 #define hehe 137731735 #define ll __int64 ll n; char s[N]; ll x[N], y[N]; ll dp[N]; int main(){ ll i,j; while(gets(s)) { dp[0] = 0; for(i=0;s[i];i++) { if(‘0‘<=s[i]&&s[i]<=‘9‘) s[i] = s[i]-‘0‘; else if(‘a‘<=s[i]&&s[i]<=‘z‘) s[i] = s[i]-‘a‘+10; else s[i] = s[i]-‘A‘+36; } ll len = i; x[0] = 0; ll dou = 1; for(i=1;i<=len;i++){ x[i] = (x[i-1]+s[i-1]*dou)%mod; dou = (dou*hehe)%mod; } y[len+1] = 0; for(i=1;i<=len;i++) { y[i] = (y[i-1]*hehe+s[i-1])%mod;} ll ans = 0; for(i=1;i<=len;i++) if(x[i]==y[i]) { dp[i] = dp[i>>1]+1; ans += dp[i]; } cout<<ans<<endl; } return 0; }
CodeForces 7D Palindrome Degree 字符串hash
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。