zoukankan      html  css  js  c++  java
  • 【SP7586】NUMOFPAL

    题面

    https://www.luogu.org/problem/SP7586

    题解

    #include<cstdio>
    #include<iostream>
    #include<cstring>
    #define ri register int
    #define N 11000050
    #define uLL unsigned long long
    using namespace std;
    char s0[N];
    char s1[N<<1];
    int n;
    int hw[N<<1],maxr,mid;
    int main(){
      scanf("%s",s0+1);
      n=strlen(s0+1);
      for (ri i=1;i<=2*n+1;i++) if (i%2==1) s1[i]='#'; else s1[i]=s0[i/2];
      maxr=0; mid=0;
      for (ri i=1;i<=2*n+1;i++) {
        if (i<=maxr) hw[i]=min(hw[2*mid-i],maxr-i);
        while (i+hw[i]+1<=2*n+1 && i-hw[i]-1>=1 && s1[i+hw[i]+1]==s1[i-hw[i]-1]) hw[i]++;
        if (i+hw[i]>maxr) maxr=i+hw[i],mid=i;
      }
      uLL ans=0;
      for (ri i=1;i<=2*n+1;i++) if (s1[i]=='#') ans+=hw[i]/2; else ans+=hw[i]/2+1;
      cout<<ans<<endl;
    }
  • 相关阅读:
    Linux tmux 工具
    HTML 注释
    HTML 引用
    HTML 格式化
    /etc/services
    Linux ss 命令
    Python cookielib 模块
    爬取需要登录的页面
    hasattr() 、getattr() 、setattr()
    爬取文本
  • 原文地址:https://www.cnblogs.com/shxnb666/p/11279708.html
Copyright © 2011-2022 走看看