結果

問題 No.319 happy b1rthday 2 me
ユーザー maspy
提出日時 2020-03-17 23:20:57
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 1,315 bytes
コンパイル時間 85 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-11-30 23:25:46
合計ジャッジ時間 2,064 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

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))
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0