zoukankan      html  css  js  c++  java
  • bzoj 2342: [Shoi2011]双倍回文

    2333,做这个题的时候IQ--,不说了,GG

     1 #include <cstdio>
     2 #include <cstring>
     3 #include <cmath>
     4 #include <algorithm>
     5 #include <iostream>
     6 #include <set>
     7 #define LL long long
     8 using namespace std;
     9 
    10 const int maxn=500000+10;
    11 
    12 int n,ans;
    13 char ch[maxn];
    14 int p[maxn],q[maxn];
    15 set<int> t;
    16 
    17 void manachar()
    18 {
    19     int mx=0,id=0;
    20     for (int i=1; i<=n; i++)
    21     {
    22         if (mx>=i) p[i]=min(p[2*id-i],mx-i); else p[i]=0;
    23         while (ch[i+p[i]+1]==ch[i-p[i]]) p[i]++;
    24         if (p[i]+i>mx) id=i,mx=p[i]+i;
    25     }
    26 }
    27 
    28 bool cmp(int a, int b){return a-p[a]<b-p[b];}
    29 
    30 int main()
    31 {
    32     scanf("%d%s",&n,ch+1); ch[0]='#'; manachar();
    33     for (int i=1; i<=n; i++) q[i]=i;
    34     sort(q+1,q+n+1,cmp);
    35     int now=1;
    36     for (int i=1; i<=n; i++)
    37     {
    38         while (now<=n && q[now]-p[q[now]]<=i) t.insert(q[now++]);
    39         set<int>::iterator tmp=t.upper_bound(i+p[i]/2);
    40         if (tmp!=t.begin()) ans=max(ans,(*--tmp-i)*4); 
    41     }
    42     cout<<ans<<endl;
    43     return 0;
    44 }
  • 相关阅读:
    我的省选 Day -9
    我的省选 Day -10
    我的省选 Day -11
    我的省选 Day -12
    我的省选 Day -13
    [NOI2013]快餐店
    我的省选 Day -14
    杭电多校2020第7场-E Expectation
    「联合省选2020」组合数问题
    UR#19 通用评测号
  • 原文地址:https://www.cnblogs.com/ccd2333/p/6732066.html
Copyright © 2011-2022 走看看