結果

問題 No.599 回文かい
ユーザー H3PO4H3PO4
提出日時 2020-10-06 08:53:17
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 799 bytes
コンパイル時間 251 ms
コンパイル使用メモリ 87,244 KB
実行使用メモリ 273,572 KB
最終ジャッジ日時 2023-09-27 06:24:04
合計ジャッジ時間 7,902 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
71,348 KB
testcase_01 AC 64 ms
71,384 KB
testcase_02 AC 63 ms
71,560 KB
testcase_03 AC 62 ms
71,216 KB
testcase_04 AC 71 ms
75,848 KB
testcase_05 AC 72 ms
75,840 KB
testcase_06 AC 78 ms
76,424 KB
testcase_07 AC 70 ms
75,988 KB
testcase_08 AC 74 ms
76,128 KB
testcase_09 AC 72 ms
75,840 KB
testcase_10 AC 315 ms
160,588 KB
testcase_11 AC 230 ms
131,160 KB
testcase_12 AC 353 ms
182,024 KB
testcase_13 AC 245 ms
137,736 KB
testcase_14 AC 457 ms
229,600 KB
testcase_15 MLE -
testcase_16 AC 1,446 ms
249,412 KB
testcase_17 MLE -
testcase_18 AC 62 ms
71,420 KB
testcase_19 AC 62 ms
71,216 KB
testcase_20 AC 65 ms
71,364 KB
evil_0.txt AC 421 ms
206,604 KB
権限があれば一括ダウンロードができます

ソースコード

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