結果
問題 | No.362 門松ナンバー |
ユーザー |
![]() |
提出日時 | 2020-03-12 23:12:29 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,166 ms / 3,000 ms |
コード長 | 1,151 bytes |
コンパイル時間 | 234 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 246,856 KB |
最終ジャッジ日時 | 2024-11-20 08:36:43 |
合計ジャッジ時間 | 13,893 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
#!/usr/bin/env python3.8# %%import sysread = sys.stdin.buffer.readreadline = sys.stdin.buffer.readlinereadlines = sys.stdin.buffer.readlinesfrom functools import lru_cache# %%def is_kadomatsu(a, b, c):if a == c:return Falsereturn (a < b > c) or (a > b < c)# %%@lru_cache(None)def count_kadomatsu(N, x):"""counting kadomatsu number K such that:1 <= K <= N and K = x mod 100"""if N < 100:return 0ret = 0q, r = divmod(x, 10)for i in range(10):if 100 * i + x <= N and is_kadomatsu(i, q, r):if i:ret += 1ret += count_kadomatsu((N - r) // 10, 10 * i + q)return retdef count_kadomatsu_all(N):return sum(count_kadomatsu(N, x) for x in range(100))# %%def solve(K):left = 0right = Kwhile count_kadomatsu_all(right) < K:right *= 10while left + 1 < right:mid = (left + right) // 2if count_kadomatsu_all(mid) >= K:right = midelse:left = midreturn right# %%T, *K = map(int, read().split())print('\n'.join(map(str, map(solve, K))))