結果

問題 No.599 回文かい
ユーザー wajima_wataruwajima_wataru
提出日時 2017-11-25 00:16:13
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 3,266 ms / 4,000 ms
コード長 646 bytes
コンパイル時間 356 ms
コンパイル使用メモリ 10,860 KB
実行使用メモリ 28,784 KB
最終ジャッジ日時 2023-08-18 05:37:43
合計ジャッジ時間 7,865 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,828 KB
testcase_01 AC 16 ms
7,816 KB
testcase_02 AC 16 ms
7,836 KB
testcase_03 AC 17 ms
7,884 KB
testcase_04 AC 17 ms
7,832 KB
testcase_05 AC 21 ms
7,920 KB
testcase_06 AC 17 ms
7,832 KB
testcase_07 AC 17 ms
7,896 KB
testcase_08 AC 16 ms
7,844 KB
testcase_09 AC 18 ms
7,780 KB
testcase_10 AC 22 ms
7,760 KB
testcase_11 AC 22 ms
7,832 KB
testcase_12 AC 36 ms
8,140 KB
testcase_13 AC 53 ms
8,036 KB
testcase_14 AC 3,266 ms
28,784 KB
testcase_15 AC 372 ms
9,104 KB
testcase_16 AC 16 ms
7,880 KB
testcase_17 AC 16 ms
7,780 KB
testcase_18 AC 16 ms
7,828 KB
testcase_19 AC 17 ms
7,828 KB
testcase_20 AC 16 ms
7,892 KB
evil_0.txt AC 2,289 ms
16,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10000)
S = input()
num = 1
nums = {}


def get_n(s):
    global num
    if s and s.count(s[0]) == len(s):
        num += 2 ** (len(s) // 2) - 1
        nums[s] = 2 ** (len(s) // 2) - 1
        return
    if nums.get(s):
        num += nums[s]
        return
    start_num = num
    for idx in range(len(s)):
        if len(s) <= 1 or idx + 1 > len(s) // 2:
            nums[s] = num - start_num
            return
        if s[idx] == s[len(s) - 1]:
            if s[:idx + 1] == s[len(s) - idx - 1:]:
                num += 1
                get_n(s[idx + 1:len(s) - idx - 1])


get_n(S)
print(num % 1000000007)
0