結果

問題 No.1953 8
ユーザー roarisroaris
提出日時 2022-05-21 20:49:26
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 77 ms / 2,000 ms
コード長 962 bytes
コンパイル時間 167 ms
コンパイル使用メモリ 81,828 KB
実行使用メモリ 74,904 KB
最終ジャッジ日時 2023-10-20 16:38:07
合計ジャッジ時間 6,154 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
72,776 KB
testcase_01 AC 71 ms
72,776 KB
testcase_02 AC 76 ms
74,900 KB
testcase_03 AC 69 ms
72,776 KB
testcase_04 AC 70 ms
72,776 KB
testcase_05 AC 70 ms
72,776 KB
testcase_06 AC 68 ms
72,776 KB
testcase_07 AC 69 ms
72,776 KB
testcase_08 AC 68 ms
72,776 KB
testcase_09 AC 69 ms
72,776 KB
testcase_10 AC 68 ms
72,776 KB
testcase_11 AC 69 ms
72,776 KB
testcase_12 AC 68 ms
72,776 KB
testcase_13 AC 69 ms
72,776 KB
testcase_14 AC 71 ms
72,784 KB
testcase_15 AC 70 ms
72,784 KB
testcase_16 AC 70 ms
72,784 KB
testcase_17 AC 71 ms
72,784 KB
testcase_18 AC 71 ms
72,784 KB
testcase_19 AC 70 ms
72,784 KB
testcase_20 AC 71 ms
72,932 KB
testcase_21 AC 71 ms
72,764 KB
testcase_22 AC 73 ms
73,256 KB
testcase_23 AC 72 ms
73,184 KB
testcase_24 AC 72 ms
73,456 KB
testcase_25 AC 71 ms
72,784 KB
testcase_26 AC 77 ms
74,904 KB
testcase_27 AC 77 ms
74,900 KB
testcase_28 AC 71 ms
72,784 KB
testcase_29 AC 69 ms
72,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import *

def calc(x):
    x = str(x)
    l = len(x)
    dp1 = [[[0]*2 for _ in range(2)] for _ in range(l+1)]
    dp1[0][0][0] = 1
    dp2 = [[[0]*2 for _ in range(2)] for _ in range(l+1)]
    
    for i in range(l):
        d = int(x[i])
        
        for j in range(2):
            for k in range(2):
                for n in range(10 if k else d+1):
                    add = j if n==0 else cnt[n]
                    dp1[i+1][j|(n>0)][k|(n<d)] += dp1[i][j][k]
                    dp2[i+1][j|(n>0)][k|(n<d)] += dp2[i][j][k]+dp1[i][j][k]*add
    
    return dp2[l][0][0]+dp2[l][1][0]+dp2[l][1][1]

def binary_search():
    l, r = 1, 10**18
    
    while l<=r:
        m = (l+r)//2
        
        if calc(m)>=K:
            r = m-1
        else:
            l = m+1
    
    return l

K = int(input())
cnt = defaultdict(int)
cnt[4] = 1
cnt[6] = 1
cnt[8] = 2
cnt[9] = 1
x = binary_search()

if calc(x)==K:
    print(x)
else:
    print(-1)
0