結果

問題 No.599 回文かい
ユーザー veqccveqcc
提出日時 2019-03-09 17:16:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,311 bytes
コンパイル時間 1,129 ms
コンパイル使用メモリ 94,308 KB
実行使用メモリ 101,100 KB
最終ジャッジ日時 2023-09-05 19:50:55
合計ジャッジ時間 6,358 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
evil_0.txt RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

const ll MOD = 1e9+7LL;
ll dp[10005]; // 文字列S[i:sz-i]を回文かい分解する組み合わせ数
bool checked[10005];
vector <int> z[10005];


vector <int> ZAlgorithm(const string& S) {
    int sz = S.size();
    vector <int> ret(sz);
    ret[0] = sz;
    int i = 1, j = 0;
    while (i < sz) {
        while (i+j < sz && S[j] == S[i+j]) j++;
        ret[i] = j;
        if (j == 0) { i++; continue; }
        int k = 1;
        while (i+k < sz && k+ret[k] < j) ret[i+k] = ret[k], k++;
        i += k; j -= k;
    }
    return ret;
}

ll rec(int l, int r) {
    if (r < l) return 1;
    if (checked[l]) return dp[l];

    ll ret = 1;
    int left = l, right = r;
    while (left < right) {
        if (z[l][right - l] == left - l + 1) (ret += rec(left+1, right-1)) %= MOD;
        left++; right--;
    }

    checked[l] = true;
    return dp[l] = ret;
}

int main() {
    string S;
    cin >> S;

    int sz = S.size();
    for (int i = 0; i < sz; i++) {
        z[i] = ZAlgorithm(S.substr(i, sz - i * 2));
    }

    cout << rec(0, sz-1) << "\n";
    return 0;
}
0