結果

問題 No.491 10^9+1と回文
ユーザー ノットカワズ
提出日時 2017-03-28 07:45:46
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 783 bytes
コンパイル時間 76 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-07-06 12:58:41
合計ジャッジ時間 6,136 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 2
other AC * 88 WA * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

# -*- coding: utf-8 -*-

import sys


s = input()
if int(s) < 10 ** 9 + 1:
    print(0)
    sys.exit()

index = len(s)-9
total = 0
kaibunsu_dict = {
    0: 0,
    1: 9,
    2: 18,
    3: 108,
    4: 198,
    5: 1098,
    6: 1998,
    7: 10998,
    8: 19998,
    9: 109998
}
total += kaibunsu_dict[index-1]


def gen_palindromic(k, B, l=0):
    if l == k:
        yield 0
    elif l == k - 1:
        for d in range(B):
            yield d
    else:
        begin = 1 if l == 0 else 0
        m = B ** (k - l - 1) + 1
        for d in range(begin, B):
            for n in gen_palindromic(k, B, l + 2):
                yield n * B + d * m


left_numbers = s[:index]
for x in gen_palindromic(index, 10):
    if x <= int(left_numbers):
        total += 1
len(left_numbers)
print(total)
0