結果

問題 No.599 回文かい
ユーザー pekempeypekempey
提出日時 2017-11-27 12:10:40
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 91 ms / 4,000 ms
コード長 874 bytes
コンパイル時間 607 ms
コンパイル使用メモリ 69,972 KB
実行使用メモリ 102,016 KB
最終ジャッジ日時 2023-08-18 07:17:42
合計ジャッジ時間 2,132 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 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 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 43 ms
70,852 KB
testcase_11 AC 29 ms
54,444 KB
testcase_12 AC 47 ms
75,420 KB
testcase_13 AC 32 ms
57,384 KB
testcase_14 AC 65 ms
93,608 KB
testcase_15 AC 77 ms
98,500 KB
testcase_16 AC 80 ms
95,712 KB
testcase_17 AC 91 ms
102,016 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
evil_0.txt AC 58 ms
85,280 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

const long long mod = 1e9 + 7;
int dp[5050];
int lcp[5050][5050];

void to(int &x, int y) {
  x += y;
  if (x >= mod) {
    x -= mod;
  }
}

int main() {
  string s;
  cin >> s;
  const int n = s.size();

  dp[0] = 1;

  for (int i = (n - 1) / 2; i >= 0; i--) {
    for (int j = n - 1; j >= n / 2; j--) {
      if (s[i] == s[j]) {
        lcp[i][j - n / 2] = lcp[i + 1][j - n / 2 + 1] + 1;
      } else {
        lcp[i][j - n / 2] = 0;
      }
    }
  }

  for (int i = 0; i * 2 < n; i++) {
    for (int j = i; j * 2 < n; j++) {
      // s[i..j] == s[n-1-j..n-1-i]
      if (lcp[i][n - 1 - j - n / 2] >= j - i + 1) {
        to(dp[j + 1], dp[i]);
      }
    }
  }

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

  cout << ans << endl;
}

0