結果

問題 No.599 回文かい
ユーザー H3PO4H3PO4
提出日時 2020-10-06 08:57:00
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 799 bytes
コンパイル時間 453 ms
コンパイル使用メモリ 10,796 KB
実行使用メモリ 190,180 KB
最終ジャッジ日時 2023-09-27 06:24:25
合計ジャッジ時間 13,924 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,820 KB
testcase_01 AC 14 ms
7,816 KB
testcase_02 AC 14 ms
7,808 KB
testcase_03 AC 14 ms
7,836 KB
testcase_04 AC 18 ms
8,132 KB
testcase_05 AC 17 ms
8,076 KB
testcase_06 AC 23 ms
8,220 KB
testcase_07 AC 19 ms
8,120 KB
testcase_08 AC 18 ms
8,204 KB
testcase_09 AC 18 ms
8,156 KB
testcase_10 AC 941 ms
100,452 KB
testcase_11 AC 533 ms
62,168 KB
testcase_12 AC 1,136 ms
112,900 KB
testcase_13 AC 629 ms
68,472 KB
testcase_14 AC 1,636 ms
165,460 KB
testcase_15 AC 1,814 ms
190,180 KB
testcase_16 TLE -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
evil_0.txt -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

S = input()
L = len(S)
MOD = 1_000_000_007

rev = lambda x: L - 1 - x

table = [[False] * (L // 2) for _ in range(L // 2)]
for i in range(L // 2):
    # 奇数長
    j = 0
    while i - j >= 0 and i + j < L // 2:
        if S[i - j] == S[rev(i + j)] and S[i + j] == S[rev(i - j)]:
            table[i - j][i + j] = True
            j += 1
        else:
            break

    # 偶数長
    j = 0
    while i - j >= 0 and i + j + 1 < L // 2:
        if S[i - j] == S[rev(i + j + 1)] and S[i + j + 1] == S[rev(i - j)]:
            table[i - j][i + j + 1] = True
            j += 1
        else:
            break

dp = [0] * (L // 2 + 1)
dp[0] = 1
for i in range(L // 2):
    for j in range(i, L // 2):
        if table[i][j]:
            dp[j + 1] = (dp[j + 1] + dp[i]) % MOD
print(sum(dp) % MOD)
0