結果

問題 No.2025 Select $k$-th Submultiset
ユーザー hahho28hahho28
提出日時 2022-07-09 10:09:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 615 ms / 2,000 ms
コード長 774 bytes
コンパイル時間 254 ms
コンパイル使用メモリ 87,244 KB
実行使用メモリ 86,668 KB
最終ジャッジ日時 2023-09-20 03:31:07
合計ジャッジ時間 18,483 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,388 KB
testcase_01 AC 73 ms
71,444 KB
testcase_02 AC 84 ms
76,044 KB
testcase_03 AC 506 ms
86,668 KB
testcase_04 AC 462 ms
86,312 KB
testcase_05 AC 578 ms
84,524 KB
testcase_06 AC 541 ms
83,216 KB
testcase_07 AC 555 ms
85,708 KB
testcase_08 AC 548 ms
84,576 KB
testcase_09 AC 587 ms
85,152 KB
testcase_10 AC 577 ms
84,888 KB
testcase_11 AC 556 ms
84,680 KB
testcase_12 AC 615 ms
85,512 KB
testcase_13 AC 547 ms
84,748 KB
testcase_14 AC 589 ms
85,376 KB
testcase_15 AC 565 ms
85,132 KB
testcase_16 AC 584 ms
85,100 KB
testcase_17 AC 559 ms
84,956 KB
testcase_18 AC 599 ms
84,020 KB
testcase_19 AC 570 ms
83,984 KB
testcase_20 AC 581 ms
84,240 KB
testcase_21 AC 597 ms
84,008 KB
testcase_22 AC 551 ms
83,884 KB
testcase_23 AC 604 ms
84,832 KB
testcase_24 AC 593 ms
84,228 KB
testcase_25 AC 75 ms
71,392 KB
testcase_26 AC 73 ms
71,308 KB
testcase_27 AC 73 ms
71,276 KB
testcase_28 AC 75 ms
71,380 KB
testcase_29 AC 76 ms
71,428 KB
testcase_30 AC 74 ms
71,424 KB
testcase_31 AC 74 ms
71,696 KB
testcase_32 AC 73 ms
71,588 KB
testcase_33 AC 75 ms
71,632 KB
testcase_34 AC 74 ms
71,284 KB
testcase_35 AC 74 ms
71,276 KB
testcase_36 AC 90 ms
76,088 KB
testcase_37 AC 73 ms
71,456 KB
testcase_38 AC 75 ms
71,596 KB
testcase_39 AC 74 ms
71,336 KB
testcase_40 AC 76 ms
71,336 KB
testcase_41 AC 74 ms
71,592 KB
testcase_42 AC 75 ms
71,308 KB
testcase_43 AC 74 ms
71,248 KB
testcase_44 AC 75 ms
71,420 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import bisect

n, k = map(int, input().split())
c = list(map(int, input().split()))

# dp[i][j] := c[i:]を使って長さj未満の部分列を作る場合の通り数
dp = [[0] + [1] * (k + 1) for _ in range(n + 1)]

for i in reversed(range(n)):
    for j in range(1, k + 2):
        dp[i][j] = dp[i + 1][j] - dp[i + 1][max(j - c[i] - 1, 0)] + dp[i][j - 1]

m = int(input())

for _ in range(m):
    q = int(input()) - 1
    if q >= dp[0][-1] - dp[0][-2]:
        print(-1)
        continue
    res = [0] * n
    remaining = k + 1
    for i in range(n):
        offset = dp[i + 1][max(remaining - c[i] - 1, 0)]
        j = bisect(dp[i + 1], q + offset)
        q -= dp[i + 1][j - 1] - offset
        res[i] = remaining - j
        remaining = j
    print(*res)
0