結果
| 問題 |
No.362 門松ナンバー
|
| コンテスト | |
| ユーザー |
maspy
|
| 提出日時 | 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 sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from functools import lru_cache
# %%
def is_kadomatsu(a, b, c):
if a == c:
return False
return (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 0
ret = 0
q, r = divmod(x, 10)
for i in range(10):
if 100 * i + x <= N and is_kadomatsu(i, q, r):
if i:
ret += 1
ret += count_kadomatsu((N - r) // 10, 10 * i + q)
return ret
def count_kadomatsu_all(N):
return sum(count_kadomatsu(N, x) for x in range(100))
# %%
def solve(K):
left = 0
right = K
while count_kadomatsu_all(right) < K:
right *= 10
while left + 1 < right:
mid = (left + right) // 2
if count_kadomatsu_all(mid) >= K:
right = mid
else:
left = mid
return right
# %%
T, *K = map(int, read().split())
print('\n'.join(map(str, map(solve, K))))
maspy