結果

問題 No.599 回文かい
ユーザー goodbatongoodbaton
提出日時 2019-02-20 11:47:49
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 179 ms / 4,000 ms
コード長 1,736 bytes
コンパイル時間 791 ms
コンパイル使用メモリ 95,176 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-06 07:03:16
合計ジャッジ時間 2,868 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 39 ms
4,384 KB
testcase_11 AC 24 ms
4,376 KB
testcase_12 AC 42 ms
4,376 KB
testcase_13 AC 25 ms
4,380 KB
testcase_14 AC 88 ms
4,380 KB
testcase_15 AC 81 ms
4,380 KB
testcase_16 AC 157 ms
4,376 KB
testcase_17 AC 179 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
evil_0.txt AC 57 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
    out << "{" << p.first << ", " << p.second << "}";
    return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

/* Zalgorithm */

// A[i] := S と S[i:|S|-1] の最長共通接頭辞の長さ

void Zalgorithm(const char *S, int *A){
  int i = 1, j = 0, k, n = strlen(S);
  A[0] = n;
  while (i < n) {
    while (i+j < n && S[j] == S[i+j]) j++;
    A[i] = j;
    if (j == 0) { i++; continue; }
    for (k = 1; i+k < n && k+A[k] < j; k++) A[i+k] = A[k];
    i += k; j -= k;
  }
}

ll dp[SIZE];
int a[SIZE];

int main(){
  char s[SIZE];
  int n;

  scanf("%s", s);
  n = strlen(s);

  dp[0] = 1;

  for(int i=0;i<n/2;i++){
    Zalgorithm(s+i, a+i);

    for(int j=0;i+j<n/2;j++)
      if(a[n-1-i-j] > j)
        dp[i+j+1] = (dp[i+j+1] + dp[i]) % mod;
  }

  ll ans = 0;

  for(int i=0;i<=n/2;i++)
    ans += dp[i];

  cout << ans % mod << endl;

  return 0;
}
0