結果
問題 | No.319 happy b1rthday 2 me |
ユーザー |
![]() |
提出日時 | 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 |
ソースコード
#!/usr/bin/env python3.8import sysread = sys.stdin.buffer.readreadline = sys.stdin.buffer.readlinereadlines = sys.stdin.buffer.readlinesfrom functools import lru_cache@lru_cache(None)def count12(L, R):if L == R:return str(L).count('12')if L > R:return 0x = (L - 12 + 99) // 100y = (R - 12) // 100ret = y - x + 1for i in range(10):x = (L - i + 9) // 10y = (R - i) // 10ret += count12(x, y)return retdef 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 = 0for keta in range(0, 20):low = 2 * (10 ** keta)high = 3 * (10 ** keta) - 1if low < L:low = Lif high > R:high = Rif low <= high:ret += high - low + 1return retx = (L - 1 + 9) // 10y = (R - 1) // 10return 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 += 1return retA, B = map(int, read().split())print(solve(A, B))