結果

問題 No.599 回文かい
ユーザー H3PO4H3PO4
提出日時 2020-10-07 20:53:36
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 809 bytes
コンパイル時間 862 ms
コンパイル使用メモリ 87,068 KB
実行使用メモリ 665,636 KB
最終ジャッジ日時 2023-09-27 09:56:27
合計ジャッジ時間 12,177 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
70,908 KB
testcase_01 AC 62 ms
71,060 KB
testcase_02 AC 64 ms
71,192 KB
testcase_03 AC 63 ms
71,244 KB
testcase_04 AC 74 ms
75,996 KB
testcase_05 AC 74 ms
76,152 KB
testcase_06 AC 84 ms
76,172 KB
testcase_07 AC 74 ms
76,240 KB
testcase_08 AC 73 ms
76,176 KB
testcase_09 AC 74 ms
75,876 KB
testcase_10 AC 280 ms
77,088 KB
testcase_11 AC 201 ms
77,040 KB
testcase_12 AC 261 ms
79,656 KB
testcase_13 AC 169 ms
77,968 KB
testcase_14 AC 320 ms
77,004 KB
testcase_15 AC 416 ms
78,956 KB
testcase_16 MLE -
testcase_17 MLE -
testcase_18 AC 182 ms
71,276 KB
testcase_19 AC 65 ms
71,272 KB
testcase_20 AC 66 ms
71,152 KB
evil_0.txt AC 286 ms
78,112 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

rev = lambda x: L - 1 - x
pair2int = lambda i, j: i * L + j

st = set()
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)]:
            st.add(pair2int(i - j, i + j))
            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)]:
            st.add(pair2int(i - j, i + j + 1))
            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 pair2int(i, j) in st:
            dp[j + 1] = (dp[j + 1] + dp[i]) % MOD
print(sum(dp) % MOD)
0