結果

問題 No.2934 Digit Sum
ユーザー 👑 rin204
提出日時 2024-10-13 16:18:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 864 ms / 2,000 ms
コード長 754 bytes
コンパイル時間 609 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 90,252 KB
最終ジャッジ日時 2024-10-13 16:18:57
合計ジャッジ時間 4,026 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.set_int_max_str_digits(10**7)

n, K = map(int, input().split())

if K == 1:
    print(1)
    exit()

now = [1]
dp = [now]
while sum(now) <= K:
    le = len(now)
    nex = [0] * (le + 9)
    for i in range(le):
        for j in range(10):
            nex[i + j] += now[i]

    now = nex[:]
    if len(now) > n + 1:
        now = now[: n + 1]

    dp.append(now)

le = len(dp)
ma = len(dp[-1])
for i in range(le):
    dp[i] += [0] * (ma - len(dp[i]))
    for j in range(len(dp[i]) - 1):
        dp[i][j + 1] += dp[i][j]

n = len(dp[-2]) - 1
ans = 0
for i in range(le - 2, -1, -1):
    for j in range(10):
        if dp[i][n - j] > K:
            ans = 10 * ans + j
            n -= j
            break
        K -= dp[i][n - j]

print(ans)
0