結果

問題 No.765 ukuku 2
ユーザー beetbeet
提出日時 2019-02-22 17:44:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,642 bytes
コンパイル時間 1,972 ms
コンパイル使用メモリ 207,976 KB
実行使用メモリ 12,476 KB
最終ジャッジ日時 2024-05-03 16:05:57
合計ジャッジ時間 3,983 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 WA -
testcase_06 AC 2 ms
6,944 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 1 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 WA -
testcase_12 AC 2 ms
6,940 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 1 ms
6,940 KB
testcase_21 AC 1 ms
6,940 KB
testcase_22 AC 1 ms
6,944 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 2 ms
6,940 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 22 ms
12,472 KB
testcase_34 AC 22 ms
12,340 KB
testcase_35 AC 20 ms
12,476 KB
testcase_36 WA -
testcase_37 AC 26 ms
12,340 KB
testcase_38 AC 26 ms
12,476 KB
testcase_39 WA -
testcase_40 AC 16 ms
10,392 KB
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
権限があれば一括ダウンロードができます

ソースコード

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];
  }
};


vector<int> manacher(string s){
  int n=s.size();
  vector<int> v(n);
  for(int i=0,j=0;i<n;){
    while(i-j>=0&&i+j<n&&s[i-j]==s[i+j]) j++;
    v[i]=j;
    int k=1;
    while(i-k>=0&&i+k<n&&k+v[i-k]<j) v[i+k]=v[i-k],k++;
    i+=k;j-=k;
  }
  return v;
}

//INSERT ABOVE HERE
signed main(){
  string s;
  cin>>s;
  int n=s.size();
  string t(s);
  reverse(t.begin(),t.end());

  RollingHash rhs(s),rht(t);
  int ans=0;

  {
    string x;
    x.push_back('$');
    for(char c:s){
      x.push_back(c);
      x.push_back('$');
    }
    int ans1=0,ans2=0;
    auto v=manacher(x);
    for(int i=0;i<n*2+1;i++){
      if(i&1) chmax(ans1,v[i]-1);
      else chmax(ans2,v[i]-1);
    }
    if(ans1==n) ans1-=1;
    if(ans2==n) ans2-=2;
    chmax(ans,ans1);
    chmax(ans,ans2);
  }
  
  // erase i
  for(int i=1;i+1<n;i++){
    int l=0,r=min(i+1,n-i);
    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;
    }
  }
  
  cout<<ans<<endl;
  return 0;
}
0