結果

問題 No.599 回文かい
ユーザー ei1333333ei1333333
提出日時 2017-11-24 23:05:15
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 265 ms / 4,000 ms
コード長 1,048 bytes
コンパイル時間 3,835 ms
コンパイル使用メモリ 199,864 KB
実行使用メモリ 198,724 KB
最終ジャッジ日時 2023-08-18 05:09:16
合計ジャッジ時間 5,254 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 4 ms
8,220 KB
testcase_05 AC 3 ms
6,304 KB
testcase_06 AC 3 ms
8,104 KB
testcase_07 AC 4 ms
8,260 KB
testcase_08 AC 4 ms
8,312 KB
testcase_09 AC 3 ms
6,396 KB
testcase_10 AC 145 ms
137,216 KB
testcase_11 AC 92 ms
105,336 KB
testcase_12 AC 152 ms
146,020 KB
testcase_13 AC 102 ms
110,844 KB
testcase_14 AC 226 ms
178,456 KB
testcase_15 AC 236 ms
191,680 KB
testcase_16 AC 226 ms
186,444 KB
testcase_17 AC 265 ms
198,724 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
evil_0.txt AC 176 ms
163,404 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;

short LCP[10001][10001];

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;
    }
  }


  int dp[10000] = {}; // dp[i]: [0, i) が分割済みのときの組み合わせ
  dp[0] = 1;
  for(int i = 0; i < S.size() / 2; i++) {
    int j = (int) S.size() - i - 1;
    // cout << "[0," << i << "]" << " [" << j << "," << S.size() - 1 << "]" << endl;
    int ret = 0;
    for(int k = i; k >= 0; k--) { // 前回の分割終了位置
      // [k, i]==[l,l+(i-k)] だったら遷移OK
      const int l = (int) S.size() - i - 1;
      if(LCP[k][l] >= i - k + 1) (ret += dp[k]) %= mod;
      // cout << "[" << k << "," << i << "]" << " [" << l << "," << l + (i - k) << "]" << endl;
    }
    dp[i + 1] = ret;
  }

  int all = 0;
  for(int i = 0; i < S.size(); i++) {
    (all += dp[i]) %= mod;
  }
  cout << all << endl;
}
0