結果

問題 No.464 PPAP
ユーザー beetbeet
提出日時 2018-11-12 11:27:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 1,102 bytes
コンパイル時間 3,263 ms
コンパイル使用メモリ 203,400 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-23 12:39:37
合計ジャッジ時間 5,246 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 4 ms
4,376 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 4 ms
4,380 KB
testcase_10 AC 63 ms
4,376 KB
testcase_11 AC 35 ms
4,376 KB
testcase_12 AC 55 ms
4,376 KB
testcase_13 AC 49 ms
4,376 KB
testcase_14 AC 50 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 49 ms
4,380 KB
testcase_24 AC 50 ms
4,380 KB
testcase_25 AC 49 ms
4,380 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());

  RollingHash rs(s),rt(t);
  auto check=[&](int l,int r){
               return rs.find(l,r)==rt.find(n-r,n-l);
             };
  
  vector<int> dp(n+1,0);
  for(int r=1;r<=n;r++)
    for(int m=1;m<r;m++)
      dp[r]+=check(0,m)&&check(m,r);
  
  Int ans=0;
  for(int i=0;i<n;i++)
    for(int j=i+1;j<n;j++)
      if(check(j,n)) ans+=dp[i];

  cout<<ans<<endl;
  return 0;
}
0