結果

問題 No.599 回文かい
ユーザー finefine
提出日時 2017-11-24 22:59:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,594 ms / 4,000 ms
コード長 814 bytes
コンパイル時間 1,582 ms
コンパイル使用メモリ 171,040 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-05-05 11:20:00
合計ジャッジ時間 9,748 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 3 ms
6,944 KB
testcase_07 AC 3 ms
6,948 KB
testcase_08 AC 3 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 493 ms
6,940 KB
testcase_11 AC 260 ms
6,940 KB
testcase_12 AC 580 ms
6,944 KB
testcase_13 AC 295 ms
6,940 KB
testcase_14 AC 931 ms
6,940 KB
testcase_15 AC 1,118 ms
6,944 KB
testcase_16 AC 1,349 ms
6,944 KB
testcase_17 AC 1,594 ms
6,944 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 AC 2 ms
6,940 KB
evil_0.txt AC 757 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

string s;
int n;

ll dp[10005];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> s;
    n = s.length();
    dp[(n - 1) / 2] = 1;
    if (n % 2 == 0) dp[(n - 1) / 2] += (s[(n - 1) / 2] == s[(n - 1) / 2 + 1]);
    for (int i = (n - 1) / 2 - 1; i >= 0; i--) {
        dp[i] = 1;
        string sl = "", sr = "";
        for (int j = i + 1; j <= (n - 1) / 2; j++) {
            sl += s[j - 1];
            sr = s[n - j] + sr;
            if (sl == sr) (dp[i] += dp[j]) %= MOD;
        }
        if (n % 2 == 0) {
            sl += s[(n - 1) / 2];
            sr = s[(n - 1) / 2 + 1] + sr;
            if (sl == sr) (dp[i] += 1) %= MOD;
        }
    }
    cout << dp[0] << endl;
    return 0;
}
0