結果

問題 No.1872 Dictionary Order
ユーザー shiomusubi496shiomusubi496
提出日時 2022-03-11 16:08:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 213 ms / 2,000 ms
コード長 715 bytes
コンパイル時間 179 ms
コンパイル使用メモリ 81,816 KB
実行使用メモリ 107,580 KB
最終ジャッジ日時 2023-10-19 12:34:16
合計ジャッジ時間 4,975 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 213 ms
107,580 KB
testcase_01 AC 45 ms
59,572 KB
testcase_02 AC 128 ms
90,500 KB
testcase_03 AC 53 ms
66,296 KB
testcase_04 AC 143 ms
90,672 KB
testcase_05 AC 46 ms
61,632 KB
testcase_06 AC 75 ms
73,372 KB
testcase_07 AC 64 ms
70,504 KB
testcase_08 AC 44 ms
62,000 KB
testcase_09 AC 57 ms
66,140 KB
testcase_10 AC 68 ms
70,412 KB
testcase_11 AC 117 ms
89,676 KB
testcase_12 AC 56 ms
68,472 KB
testcase_13 AC 53 ms
66,140 KB
testcase_14 AC 112 ms
88,960 KB
testcase_15 AC 124 ms
90,756 KB
testcase_16 AC 44 ms
62,168 KB
testcase_17 AC 66 ms
72,544 KB
testcase_18 AC 78 ms
72,748 KB
testcase_19 AC 65 ms
70,408 KB
testcase_20 AC 57 ms
66,296 KB
testcase_21 AC 97 ms
86,588 KB
testcase_22 AC 175 ms
91,228 KB
testcase_23 AC 109 ms
84,944 KB
testcase_24 AC 76 ms
72,560 KB
testcase_25 AC 133 ms
89,776 KB
testcase_26 AC 75 ms
72,560 KB
testcase_27 AC 132 ms
89,144 KB
testcase_28 AC 164 ms
91,284 KB
testcase_29 AC 170 ms
91,252 KB
testcase_30 AC 51 ms
63,724 KB
testcase_31 AC 180 ms
91,200 KB
testcase_32 AC 34 ms
53,392 KB
testcase_33 AC 34 ms
53,392 KB
testcase_34 AC 40 ms
59,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, M = map(int, input().split())
A = list(map(int, input().split()))

dp = [[False] * (M + 1) for _ in range(N + 1)]
dp[N][0] = True
for i in range(N-1, -1, -1):
    for j in range(M + 1):
        dp[i][j] = dp[i + 1][j]
    for j in range(A[i], M + 1):
        dp[i][j] = dp[i][j] or dp[i + 1][j - A[i]]

if not dp[0][M]:
    print(-1)
    exit()

L = list(map(int, input().split()))
P = [0] * N
for i in range(N):
    P[L[i] - 1] = i

now = M
ans = [-1]

while now != 0:
    for i in range(N):
        if ans[-1] > P[i]:
            continue
        if now >= A[P[i]] and dp[P[i] + 1][now - A[P[i]]]:
            ans += [P[i] + 1]
            now -= A[P[i]]
            break

print(len(ans) - 1)
print(*ans[1:])
0