結果
問題 | No.2025 Select $k$-th Submultiset |
ユーザー | LyricalMaestro |
提出日時 | 2024-09-03 03:16:16 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 501 ms / 2,000 ms |
コード長 | 2,261 bytes |
コンパイル時間 | 338 ms |
コンパイル使用メモリ | 82,300 KB |
実行使用メモリ | 87,392 KB |
最終ジャッジ日時 | 2024-09-03 03:16:33 |
合計ジャッジ時間 | 15,660 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
53,240 KB |
testcase_01 | AC | 38 ms
53,184 KB |
testcase_02 | AC | 48 ms
62,900 KB |
testcase_03 | AC | 288 ms
85,548 KB |
testcase_04 | AC | 345 ms
86,688 KB |
testcase_05 | AC | 501 ms
85,608 KB |
testcase_06 | AC | 444 ms
85,168 KB |
testcase_07 | AC | 386 ms
85,744 KB |
testcase_08 | AC | 473 ms
86,472 KB |
testcase_09 | AC | 446 ms
86,280 KB |
testcase_10 | AC | 480 ms
85,928 KB |
testcase_11 | AC | 442 ms
85,940 KB |
testcase_12 | AC | 472 ms
87,392 KB |
testcase_13 | AC | 446 ms
86,244 KB |
testcase_14 | AC | 479 ms
86,208 KB |
testcase_15 | AC | 463 ms
86,148 KB |
testcase_16 | AC | 446 ms
86,148 KB |
testcase_17 | AC | 431 ms
85,968 KB |
testcase_18 | AC | 468 ms
85,476 KB |
testcase_19 | AC | 446 ms
84,552 KB |
testcase_20 | AC | 476 ms
84,868 KB |
testcase_21 | AC | 435 ms
85,432 KB |
testcase_22 | AC | 465 ms
85,584 KB |
testcase_23 | AC | 438 ms
85,932 KB |
testcase_24 | AC | 424 ms
85,592 KB |
testcase_25 | AC | 39 ms
53,136 KB |
testcase_26 | AC | 39 ms
54,668 KB |
testcase_27 | AC | 39 ms
53,440 KB |
testcase_28 | AC | 40 ms
54,228 KB |
testcase_29 | AC | 39 ms
53,568 KB |
testcase_30 | AC | 39 ms
54,664 KB |
testcase_31 | AC | 40 ms
54,256 KB |
testcase_32 | AC | 39 ms
53,724 KB |
testcase_33 | AC | 38 ms
52,960 KB |
testcase_34 | AC | 38 ms
53,180 KB |
testcase_35 | AC | 38 ms
53,012 KB |
testcase_36 | AC | 54 ms
64,840 KB |
testcase_37 | AC | 41 ms
53,880 KB |
testcase_38 | AC | 40 ms
53,604 KB |
testcase_39 | AC | 38 ms
53,424 KB |
testcase_40 | AC | 38 ms
53,144 KB |
testcase_41 | AC | 38 ms
52,764 KB |
testcase_42 | AC | 38 ms
52,924 KB |
testcase_43 | AC | 38 ms
53,196 KB |
testcase_44 | AC | 38 ms
53,748 KB |
ソースコード
## https://yukicoder.me/problems/no/2025 def main(): N, L = map(int, input().split()) C = list(map(int, input().split())) Q = int(input()) K = [] for _ in range(Q): K.append((int(input()))) # dpを使って利用する個数を計算 dp = [[0] * (L + 1) for _ in range(N)] dp[0][0] = 1 cum_dp = [[0] * (L + 1) for _ in range(N)] cum_ = 0 for i in range(L + 1): cum_ += dp[0][i] cum_dp[0][i] = cum_ for i in range(N - 1): c = C[-i-1] for j in range(L + 1): if j - c - 1 >= 0: dp[i + 1][j] = cum_dp[i][j] - cum_dp[i][j - c - 1] else: dp[i + 1][j] = cum_dp[i][j] cum_ = 0 for j in range(L + 1): cum_ += dp[i + 1][j] cum_dp[i + 1][j] = cum_ # k_iごとに求めていく for k in K: rest_l = L answer = [] k0 = k for j in range(N - 1): c = C[j] def fn(value): l = max(rest_l - c, 0) if l == 0: return cum_dp[-j - 1][value] else: return cum_dp[-j - 1][value] - cum_dp[-j - 1][l - 1] if fn(rest_l) < k0: answer = -1 break low = max(rest_l - c, 0) if fn(low) >= k0: v = low else: high = rest_l while high - low > 1: mid = (high + low) // 2 if fn(mid) < k0: low = mid else: high = mid if fn(high) < k0: v = high + 1 else: v = low + 1 used_c1 = rest_l - v answer.append(used_c1) if v > max(rest_l - c, 0): k0 = k0 - fn(v - 1) rest_l = v if answer == -1: print(answer) else: sum_c = sum(answer) x = L - sum_c answer.append(x) print(" ".join(map(str, answer))) if __name__ == "__main__": main()