結果

問題 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,946 ms / 4,000 ms
コード長 646 bytes
コンパイル時間 86 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 31,360 KB
最終ジャッジ日時 2024-05-05 11:50:35
合計ジャッジ時間 8,718 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
10,624 KB
testcase_01 AC 27 ms
10,752 KB
testcase_02 AC 25 ms
10,624 KB
testcase_03 AC 28 ms
10,624 KB
testcase_04 AC 30 ms
10,496 KB
testcase_05 AC 35 ms
10,752 KB
testcase_06 AC 27 ms
10,496 KB
testcase_07 AC 28 ms
10,624 KB
testcase_08 AC 28 ms
10,624 KB
testcase_09 AC 29 ms
10,624 KB
testcase_10 AC 38 ms
10,752 KB
testcase_11 AC 33 ms
10,752 KB
testcase_12 AC 50 ms
10,880 KB
testcase_13 AC 70 ms
10,880 KB
testcase_14 AC 3,946 ms
31,360 KB
testcase_15 AC 423 ms
11,776 KB
testcase_16 AC 30 ms
10,624 KB
testcase_17 AC 29 ms
10,624 KB
testcase_18 AC 30 ms
10,752 KB
testcase_19 AC 29 ms
10,752 KB
testcase_20 AC 29 ms
10,624 KB
evil_0.txt AC 2,640 ms
19,456 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