結果

問題 No.1953 8
ユーザー siro53siro53
提出日時 2022-05-21 00:46:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 88 ms / 2,000 ms
コード長 1,374 bytes
コンパイル時間 295 ms
コンパイル使用メモリ 81,844 KB
実行使用メモリ 76,124 KB
最終ジャッジ日時 2023-10-20 15:19:42
合計ジャッジ時間 6,365 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
70,552 KB
testcase_01 AC 70 ms
73,776 KB
testcase_02 AC 80 ms
75,932 KB
testcase_03 AC 60 ms
70,552 KB
testcase_04 AC 58 ms
70,552 KB
testcase_05 AC 60 ms
70,552 KB
testcase_06 AC 58 ms
70,552 KB
testcase_07 AC 58 ms
70,552 KB
testcase_08 AC 58 ms
70,552 KB
testcase_09 AC 56 ms
70,552 KB
testcase_10 AC 58 ms
70,552 KB
testcase_11 AC 59 ms
70,552 KB
testcase_12 AC 72 ms
74,616 KB
testcase_13 AC 87 ms
75,868 KB
testcase_14 AC 83 ms
75,868 KB
testcase_15 AC 78 ms
75,864 KB
testcase_16 AC 81 ms
75,876 KB
testcase_17 AC 83 ms
75,864 KB
testcase_18 AC 79 ms
76,124 KB
testcase_19 AC 79 ms
75,920 KB
testcase_20 AC 83 ms
75,864 KB
testcase_21 AC 77 ms
75,864 KB
testcase_22 AC 79 ms
75,864 KB
testcase_23 AC 81 ms
75,864 KB
testcase_24 AC 83 ms
75,864 KB
testcase_25 AC 83 ms
75,864 KB
testcase_26 AC 88 ms
75,936 KB
testcase_27 AC 80 ms
75,932 KB
testcase_28 AC 78 ms
75,864 KB
testcase_29 AC 80 ms
75,864 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

K = int(input())

def check(N):
    a = [1, 0, 0, 0, 1, 0, 1, 0, 2, 1]
    sz = len(str(N))
    # dp_sub[上からi桁目まで見て][N未満かどうか][leadingzero中] = 通り数
    dp_sub = [[[0, 0], [0, 0]] for _ in range(sz + 1)]
    # dp[上からi桁目まで見て][N未満かどうか][leadingzero中] = ○のsum
    dp = [[[0, 0], [0, 0]] for _ in range(sz + 1)]
    dp_sub[0][0][1] = 1

    for i in range(sz):
        d = int(str(N)[i])
        for isless in range(2):
            for islz in range(2):
                for num in range(10):
                    if isless == 0 and num > d:
                        continue
                    isless2 = 1 if num < d else isless
                    islz2 = 0 if num != 0 else islz
                    dp_sub[i+1][isless2][islz2] += dp_sub[i][isless][islz]
                    val = 0
                    if islz2 == 0:
                        val += dp_sub[i][isless][islz] * a[num]
                    dp[i+1][isless2][islz2] += dp[i][isless][islz] + val
        # print(i, dp[i], dp_sub[i])
    # print(sz, dp[sz], dp_sub[sz])
    ret = 0
    for isless in range(2):
        ret += dp[sz][isless][0]
    return ret

# print(check(K))

ok, ng = 10**18 + 1, 0
while ok - ng > 1:
    mid = (ok + ng) // 2
    if check(mid) >= K:
        ok = mid
    else:
        ng = mid

print(ok if check(ok) == K else -1)
0