結果

問題 No.491 10^9+1と回文
ユーザー maspymaspy
提出日時 2020-02-25 13:50:29
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 838 bytes
コンパイル時間 177 ms
コンパイル使用メモリ 12,416 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-10-13 12:13:46
合計ジャッジ時間 5,676 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 42 WA * 61
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# %%
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


from functools import lru_cache

# %%
N = int(read())
bound = N // (10 ** 9 + 1)


# %%
@lru_cache(None)
def cnt_palindrome(keta, N, leading_0):
    N = min(10 ** keta - 1, N)
    if keta == 1:
        return N + 1 if leading_0 else N
    if keta == 2:
        return N // 11 + 1 if leading_0 else N // 11
    x = 10 ** (keta - 1) + 1
    low = 0 if leading_0 else 1
    ret = 0
    for i in range(low, 10):
        M = (N - x * i) // 10
        M = min(10 ** (keta - 2) - 1, M, True)
        if M < 0:
            break
        ret += cnt_palindrome(keta - 2, M, True)
    return ret


# %%
answer = 0
for keta in range(1, 10):
    answer += cnt_palindrome(keta, bound, False)
print(answer)
0