結果

問題 No.765 ukuku 2
ユーザー beetbeet
提出日時 2019-02-22 18:34:37
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 57 ms / 3,000 ms
コード長 2,593 bytes
コンパイル時間 2,261 ms
コンパイル使用メモリ 203,340 KB
実行使用メモリ 9,896 KB
最終ジャッジ日時 2023-08-16 08:47:00
合計ジャッジ時間 5,338 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,384 KB
testcase_14 AC 1 ms
4,384 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,384 KB
testcase_19 AC 1 ms
4,504 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,384 KB
testcase_22 AC 2 ms
4,384 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 2 ms
4,384 KB
testcase_30 AC 34 ms
8,244 KB
testcase_31 AC 35 ms
8,428 KB
testcase_32 AC 34 ms
7,144 KB
testcase_33 AC 6 ms
4,380 KB
testcase_34 AC 5 ms
4,384 KB
testcase_35 AC 50 ms
9,788 KB
testcase_36 AC 49 ms
9,868 KB
testcase_37 AC 57 ms
9,788 KB
testcase_38 AC 55 ms
9,828 KB
testcase_39 AC 52 ms
9,896 KB
testcase_40 AC 29 ms
8,508 KB
testcase_41 AC 38 ms
8,712 KB
testcase_42 AC 37 ms
9,284 KB
testcase_43 AC 37 ms
8,448 KB
testcase_44 AC 33 ms
8,764 KB
testcase_45 AC 53 ms
9,300 KB
testcase_46 AC 41 ms
8,448 KB
testcase_47 AC 39 ms
9,552 KB
testcase_48 AC 38 ms
9,516 KB
testcase_49 AC 46 ms
9,224 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}



struct RollingHash{
  using ull = unsigned long long;
  vector<ull> hash,p;
  RollingHash(){}
  RollingHash(const string &s,ull B=1000000007LL){
    int n=s.size();
    hash.assign(n+1,0);
    p.assign(n+1,1);
    for(int i=0;i<n;i++){
      hash[i+1]=hash[i]*B+s[i];
      p[i+1]=p[i]*B;
    }
  }
  //S[l, r)
  ull find(int l,int r){
    return hash[r]-hash[l]*p[r-l];
  }
};


//INSERT ABOVE HERE
signed main(){
  string s;
  cin>>s;
  int n=s.size();
  string t(s);
  reverse(t.begin(),t.end());
  if(s==t){
    cout<<n-1<<endl;
    return 0;
  }
  
  RollingHash rhs(s),rht(t);
  int ans=0;
  
  // odd
  for(int i=0;i<n;i++){    
    int l=0,r=min(i,n-(i+1))+1;
    while(l+1<r){
      int m=(l+r)>>1;
      auto x=rhs.find(i+1,i+1+m);
      auto y=rht.find(n-i,n-i+m);
      if(x==y) l=m;
      else r=m;
    }
    if(l==min(i,n-(i+1))){
      chmax(ans,l*2+1);
      continue;
    }
    int pl=l,pr=r;
    {
      l=pl;r=pr;
      int p=l;
      r=min(i,n-(i+2))+1;
      while(l+1<r){
        int m=(l+r)>>1;
        auto x=rhs.find(i+2+p,i+2+m);
        auto y=rht.find(n-i+p,n-i+m);
        if(x==y) l=m;
        else r=m;
      }
      chmax(ans,l*2+1);
    }
    {
      l=pl;r=pr;
      int p=l;
      r=min(i-1,n-(i+1))+1;
      while(l+1<r){
        int m=(l+r)>>1;
        auto x=rhs.find(i+1+p,i+1+m);
        auto y=rht.find(n-i+p+1,n-i+m+1);
        if(x==y) l=m;
        else r=m;
      }
      chmax(ans,l*2+1);
    }
  }

  // even
  for(int i=0;i+1<n;i++){
    if(s[i]!=s[i+1]) continue;
    
    int l=0,r=min(i,n-(i+2))+1;
    while(l+1<r){
      int m=(l+r)>>1;
      auto x=rhs.find(i+2,i+2+m);
      auto y=rht.find(n-i,n-i+m);
      if(x==y) l=m;
      else r=m;
    }
    if(l==min(i,n-(i+2))){
      chmax(ans,l*2+2);
      continue;
    }
    
    int pl=l,pr=r;
    {
      l=pl;r=pr;
      int p=l;
      r=min(i,n-(i+3))+1;
      while(l+1<r){
        int m=(l+r)>>1;
        auto x=rhs.find(i+3+p,i+3+m);
        auto y=rht.find(n-i+p,n-i+m);
        if(x==y) l=m;
        else r=m;
      }
      chmax(ans,l*2+2);
    }
    {
      l=pl;r=pr;
      int p=l;
      r=min(i-1,n-(i+2))+1;
      while(l+1<r){
        int m=(l+r)>>1;
        auto x=rhs.find(i+2+p,i+2+m);
        auto y=rht.find(n-i+p+1,n-i+m+1);
        if(x==y) l=m;
        else r=m;
      }
      chmax(ans,l*2+2);
    }
  }
  
  cout<<ans<<endl;
  return 0;
}
0