結果

問題 No.319 happy b1rthday 2 me
ユーザー maspymaspy
提出日時 2020-03-17 23:20:57
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 19 ms / 2,000 ms
コード長 1,315 bytes
コンパイル時間 236 ms
コンパイル使用メモリ 11,112 KB
実行使用メモリ 8,852 KB
最終ジャッジ日時 2023-08-20 19:27:44
合計ジャッジ時間 2,254 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,740 KB
testcase_01 AC 16 ms
8,668 KB
testcase_02 AC 18 ms
8,760 KB
testcase_03 AC 16 ms
8,796 KB
testcase_04 AC 17 ms
8,712 KB
testcase_05 AC 16 ms
8,852 KB
testcase_06 AC 17 ms
8,672 KB
testcase_07 AC 16 ms
8,712 KB
testcase_08 AC 17 ms
8,788 KB
testcase_09 AC 16 ms
8,808 KB
testcase_10 AC 16 ms
8,640 KB
testcase_11 AC 16 ms
8,784 KB
testcase_12 AC 17 ms
8,684 KB
testcase_13 AC 16 ms
8,676 KB
testcase_14 AC 19 ms
8,692 KB
testcase_15 AC 17 ms
8,816 KB
testcase_16 AC 16 ms
8,644 KB
testcase_17 AC 17 ms
8,684 KB
testcase_18 AC 17 ms
8,684 KB
testcase_19 AC 17 ms
8,664 KB
testcase_20 AC 17 ms
8,844 KB
testcase_21 AC 17 ms
8,804 KB
testcase_22 AC 16 ms
8,640 KB
testcase_23 AC 17 ms
8,812 KB
testcase_24 AC 17 ms
8,840 KB
testcase_25 AC 17 ms
8,760 KB
testcase_26 AC 16 ms
8,736 KB
testcase_27 AC 17 ms
8,732 KB
testcase_28 AC 17 ms
8,680 KB
testcase_29 AC 17 ms
8,756 KB
testcase_30 AC 17 ms
8,680 KB
testcase_31 AC 17 ms
8,848 KB
testcase_32 AC 17 ms
8,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from functools import lru_cache


@lru_cache(None)
def count12(L, R):
    if L == R:
        return str(L).count('12')
    if L > R:
        return 0
    x = (L - 12 + 99) // 100
    y = (R - 12) // 100
    ret = y - x + 1
    for i in range(10):
        x = (L - i + 9) // 10
        y = (R - i) // 10
        ret += count12(x, y)
    return ret


def count12_naive(L, R):
    return sum(str(n).count('12') for n in range(L, R + 1))


def count_2xx1(L, R):
    def count_2xx(L, R):
        ret = 0
        for keta in range(0, 20):
            low = 2 * (10 ** keta)
            high = 3 * (10 ** keta) - 1
            if low < L:
                low = L
            if high > R:
                high = R
            if low <= high:
                ret += high - low + 1
        return ret
    x = (L - 1 + 9) // 10
    y = (R - 1) // 10
    return count_2xx(x, y)


def count_2xx1_naive(L, R):
    return sum(str(n)[0] == '2' and n % 10 == 1 for n in range(L, R + 1))


def solve(A, B):
    ret = count12(A, B)
    if A < B:
        ret += count_2xx1(A, B - 1)
    if A <= 1 and 2 <= B:
        ret += 1
    return ret


A, B = map(int, read().split())
print(solve(A, B))
0