結果
問題 |
No.2865 Base 10 Subsets 2
|
ユーザー |
![]() |
提出日時 | 2025-03-20 18:50:57 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 38 ms / 2,000 ms |
コード長 | 1,438 bytes |
コンパイル時間 | 263 ms |
コンパイル使用メモリ | 82,352 KB |
実行使用メモリ | 54,004 KB |
最終ジャッジ日時 | 2025-03-20 18:52:35 |
合計ジャッジ時間 | 1,442 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 |
ソースコード
def main(): import sys N, K = map(int, sys.stdin.readline().split()) # Extract digits of N, LSb first (d_0 is least significant) digits_n = [] if N == 0: digits_n = [0] else: n = N while n > 0: digits_n.append(n % 10) n //= 10 m = len(digits_n) - 1 # highest digit index # Compute products array products = [1] * (m + 2) for i in range(1, m + 2): if i - 1 < len(digits_n): a_prev = digits_n[i - 1] else: a_prev = 0 products[i] = products[i - 1] * (a_prev + 1) # Determine the digits of the K-th number b_digits = [] current_K = K for i in range(m, -1, -1): a_i = digits_n[i] if i < len(digits_n) else 0 current_product = products[i] # Iterate through possible v (0 to a_i) chosen_v = a_i # default to a_i if not found earlier for v in range(a_i + 1): if current_K > current_product: current_K -= current_product else: chosen_v = v break b_digits.append(chosen_v) # Construct the number from the digits number = 0 exp = len(b_digits) - 1 # since digits are added from most to least significant for digit in b_digits: number += digit * (10 ** exp) exp -= 1 print(number) if __name__ == "__main__": main()