結果

問題 No.599 回文かい
ユーザー nebukuro09nebukuro09
提出日時 2017-11-24 22:41:42
言語 D
(dmd 2.106.1)
結果
TLE  
実行時間 -
コード長 878 bytes
コンパイル時間 652 ms
コンパイル使用メモリ 96,544 KB
実行使用メモリ 8,760 KB
最終ジャッジ日時 2023-09-03 17:00:32
合計ジャッジ時間 6,749 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;

const long MOD = 10^^9 + 7;

void main() {
    auto S = readln.chomp;
    auto N = S.length.to!int;

    int[][string] hoge;
    foreach (i; 0..N)
        foreach (j; i+1..N+1)
            hoge[S[i..j]] ~= i;


    auto mem = new long[](N);
    mem.fill(-1);

    long dfs(int l) {
        if (l >= N/2)
            return 0;
        if (mem[l] >= 0)
            return mem[l];

        int r = N - l - 1;
        long ret = 0;
        foreach (i; l..N/2) {
            if (S[l..i+1] in hoge && !(hoge[S[l..i+1]].assumeSorted.equalRange(N-i-1).empty)) {
                (ret += dfs(i+1) + 1) %= MOD;
            }
        }
        mem[l] = ret;
        return ret;
    }

    writeln(dfs(0)+1);
}
0