結果

問題 No.1953 8
ユーザー 👑 KazunKazun
提出日時 2022-04-15 00:34:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 112 ms / 2,000 ms
コード長 1,089 bytes
コンパイル時間 233 ms
コンパイル使用メモリ 87,088 KB
実行使用メモリ 77,948 KB
最終ジャッジ日時 2023-08-26 00:23:04
合計ジャッジ時間 7,715 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 102 ms
77,164 KB
testcase_01 AC 107 ms
77,336 KB
testcase_02 AC 106 ms
77,920 KB
testcase_03 AC 103 ms
77,344 KB
testcase_04 AC 102 ms
77,524 KB
testcase_05 AC 101 ms
77,428 KB
testcase_06 AC 105 ms
77,548 KB
testcase_07 AC 100 ms
77,528 KB
testcase_08 AC 103 ms
77,240 KB
testcase_09 AC 99 ms
77,456 KB
testcase_10 AC 100 ms
77,272 KB
testcase_11 AC 104 ms
77,296 KB
testcase_12 AC 101 ms
77,324 KB
testcase_13 AC 105 ms
77,424 KB
testcase_14 AC 102 ms
77,208 KB
testcase_15 AC 102 ms
77,476 KB
testcase_16 AC 101 ms
77,320 KB
testcase_17 AC 102 ms
77,412 KB
testcase_18 AC 105 ms
77,640 KB
testcase_19 AC 107 ms
77,744 KB
testcase_20 AC 106 ms
77,744 KB
testcase_21 AC 109 ms
77,728 KB
testcase_22 AC 105 ms
77,792 KB
testcase_23 AC 105 ms
77,752 KB
testcase_24 AC 112 ms
77,784 KB
testcase_25 AC 109 ms
77,948 KB
testcase_26 AC 107 ms
77,944 KB
testcase_27 AC 109 ms
77,900 KB
testcase_28 AC 107 ms
77,268 KB
testcase_29 AC 107 ms
77,304 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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