結果

問題 No.599 回文かい
ユーザー たこしたこし
提出日時 2017-11-24 22:37:36
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 958 bytes
コンパイル時間 1,372 ms
コンパイル使用メモリ 144,968 KB
実行使用メモリ 199,560 KB
最終ジャッジ日時 2023-08-18 04:52:14
合計ジャッジ時間 4,250 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
199,100 KB
testcase_01 AC 75 ms
199,100 KB
testcase_02 AC 76 ms
198,832 KB
testcase_03 AC 75 ms
198,828 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
evil_0.txt WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define INF 1145141919
#define INF_LL 114514191981036
using LL = long long int;
using ULL = unsigned long long int;
#define II pair<int, int>

using namespace std;

string S;
const LL mod = 1000000007;
const int MAX_S = 10005;

LL dp[MAX_S/2][MAX_S/2];

ULL Hash[MAX_S];
ULL BaseB[MAX_S];
ULL Base = 1000000000000009;

void reg()
{
  BaseB[0] = 1;
  for (size_t i = 0; i < S.length(); i++) {
    Hash[i+1] = Hash[i] * Base;
    Hash[i+1] += S[i];
    BaseB[i+1] = BaseB[i] * Base;
  }
}

ULL calc(int l, int r)
{
  return Hash[r] - Hash[l] * BaseB[r-l];
}

LL solve(int l, int r)
{
  if(dp[l][r] != -1) {
    return dp[l][r];
  }

  LL ret = 1;

  for (size_t i = 1; l+i < r-i; i++) {
    if(calc(l, l+i) == calc(r-i, r)) {
      ret += solve(l+i, r-i);
      ret %= mod;
    }
  }

  return dp[l][r] = ret;
}

int main()
{
  cin >> S;
  memset(dp, -1, sizeof(dp));

  reg();

  cout << solve(0, S.length()) << endl;

  return 0;
}
0