結果

問題 No.599 回文かい
ユーザー koyumeishikoyumeishi
提出日時 2017-11-07 15:56:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 156 ms / 4,000 ms
コード長 1,007 bytes
コンパイル時間 1,381 ms
コンパイル使用メモリ 71,680 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-03 06:55:16
合計ジャッジ時間 2,457 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 47 ms
5,376 KB
testcase_11 AC 29 ms
5,376 KB
testcase_12 AC 51 ms
5,376 KB
testcase_13 AC 32 ms
5,376 KB
testcase_14 AC 86 ms
5,376 KB
testcase_15 AC 92 ms
5,376 KB
testcase_16 AC 137 ms
5,376 KB
testcase_17 AC 156 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
evil_0.txt AC 66 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <vector>
#include <iostream>
#include <string>
using namespace std;

vector<int> zAlgo(const string& s){
  int n = s.size();
  vector<int> z(n, 0);
  z[0] = n;
  int l = 0, r = 0;
  for(int i=1; i<n; i++){
    if( i>r ){
      l = r = i;
      while( r<n && s[r-l] == s[r] ) r++;
      z[i] = r-l; r--;
    }else{
      int k = i-l;
      if( z[k] < r+1-i ) z[i] = z[k];
      else{
        l = i;
        while( r<n && s[r-l] == s[r] ) r++;
        z[i] = r-l; r--;
      }
    }
  }
  return z;
}

constexpr long long mod = 1000000007ll;

int main(){
  string s;
  cin >> s;

  int n = s.size();
  vector<long long> dp(n, 0);
  long long ans = 0;
  dp[0] = 1;
  for(int i=0; i<n && n-2*i>0; i++){
    int len = n-2*i;
    string sub = s.substr(i, len);
    auto z = zAlgo(sub);
    for(int j=1; j<=len/2; j++){
      if( z[len-j] == j ){
        dp[i+j] = (dp[i+j] + dp[i]) % mod;
      }
    }
  }
  for(int i=0; i<n; i++){
    ans = (ans + dp[i]) % mod;
  }
  cout << ans << endl;
  return 0;
}
0