結果

問題 No.599 回文かい
ユーザー ei1333333ei1333333
提出日時 2017-11-24 23:07:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 249 ms / 4,000 ms
コード長 564 bytes
コンパイル時間 2,233 ms
コンパイル使用メモリ 198,248 KB
実行使用メモリ 198,792 KB
最終ジャッジ日時 2023-08-18 05:10:50
合計ジャッジ時間 4,799 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 3 ms
8,152 KB
testcase_05 AC 3 ms
6,248 KB
testcase_06 AC 3 ms
7,988 KB
testcase_07 AC 4 ms
8,304 KB
testcase_08 AC 3 ms
8,228 KB
testcase_09 AC 4 ms
6,340 KB
testcase_10 AC 135 ms
137,420 KB
testcase_11 AC 82 ms
105,468 KB
testcase_12 AC 130 ms
146,072 KB
testcase_13 AC 95 ms
110,928 KB
testcase_14 AC 205 ms
178,556 KB
testcase_15 AC 237 ms
191,696 KB
testcase_16 AC 236 ms
186,196 KB
testcase_17 AC 249 ms
198,792 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
evil_0.txt AC 184 ms
163,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

const int mod = 1e9 + 7;

short LCP[10001][10001];
int dp[10000];

int main()
{
  string S;
  cin >> S;
  for(int i = S.size() - 1; i >= 0; i--) {
    for(int j = S.size() - 1; j >= 0; j--) {
      LCP[i][j] = S[i] == S[j] ? LCP[i + 1][j + 1] + 1 : 0;
    }
  }
  dp[0] = 1;
  for(int i = 0; i < S.size() / 2; i++) {
    for(int k = i; k >= 0; k--) {
      if(LCP[k][S.size() - i - 1] >= i - k + 1) {
        (dp[i + 1] += dp[k]) %= mod;
      }
    }
  }
  cout << accumulate(dp, dp + S.size(), 0LL) % mod << endl;
}
0