結果

問題 No.599 回文かい
ユーザー finefine
提出日時 2017-11-24 22:59:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,647 ms / 4,000 ms
コード長 814 bytes
コンパイル時間 1,533 ms
コンパイル使用メモリ 167,332 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-18 05:05:42
合計ジャッジ時間 9,899 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 471 ms
4,376 KB
testcase_11 AC 245 ms
4,376 KB
testcase_12 AC 557 ms
4,380 KB
testcase_13 AC 281 ms
4,376 KB
testcase_14 AC 902 ms
4,376 KB
testcase_15 AC 1,088 ms
4,376 KB
testcase_16 AC 1,395 ms
4,376 KB
testcase_17 AC 1,647 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
evil_0.txt AC 734 ms
4,380 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