题目链接:点击打开链接
#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; }
时间: 2024-10-13 15:33:30