結果
問題 |
No.1953 8
|
ユーザー |
👑 ![]() |
提出日時 | 2022-04-15 00:34:34 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 96 ms / 2,000 ms |
コード長 | 1,089 bytes |
コンパイル時間 | 558 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 71,424 KB |
最終ジャッジ日時 | 2024-12-24 12:39:03 |
合計ジャッジ時間 | 6,515 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 30 |
ソースコード
from functools import lru_cache def General_Binary_Decrease_Search_Integer(L, R, cond, default=None): """ 条件式が単調減少であるとき, 整数上で二部探索を行う. L: 解の下限 R: 解の上限 cond: 条件 (1変数関数, 広義単調減少 を満たす) default: R で条件を満たさないときの返り値 """ if not(cond(L)): return default if cond(R): return R L-=1 while R-L>1: C=L+(R-L)//2 if cond(C): L=C else: R=C return L @lru_cache(maxsize=None) def count(N): if N<10: Ans=0 for n in range(1,N+1): Ans+=A[n] return Ans q,r=divmod(N,10) x=y=0 for i in range(10): if i<=r: x+=A[i] else: y+=A[i] return count(q)*(r+1)+x*(q+1)-1+count(q-1)*(9-r)+y*q #================================================== A=[1,0,0,0,1,0,1,0,2,1] K=int(input()) N=General_Binary_Decrease_Search_Integer(0,10**18,lambda x:count(x)<=K) print(N if count(N)==K else -1)