結果

問題 No.1872 Dictionary Order
ユーザー shiomusubi496shiomusubi496
提出日時 2021-11-22 22:47:36
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 715 bytes
コンパイル時間 204 ms
コンパイル使用メモリ 11,016 KB
実行使用メモリ 40,292 KB
最終ジャッジ日時 2023-10-14 10:48:35
合計ジャッジ時間 22,112 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 AC 28 ms
8,404 KB
testcase_02 AC 619 ms
23,088 KB
testcase_03 AC 108 ms
10,416 KB
testcase_04 AC 966 ms
31,528 KB
testcase_05 AC 41 ms
8,760 KB
testcase_06 AC 434 ms
18,668 KB
testcase_07 AC 220 ms
13,504 KB
testcase_08 AC 19 ms
8,396 KB
testcase_09 AC 187 ms
12,300 KB
testcase_10 AC 316 ms
15,612 KB
testcase_11 AC 582 ms
22,256 KB
testcase_12 AC 123 ms
11,156 KB
testcase_13 AC 147 ms
11,500 KB
testcase_14 AC 549 ms
21,420 KB
testcase_15 AC 676 ms
24,616 KB
testcase_16 AC 38 ms
8,824 KB
testcase_17 AC 319 ms
16,232 KB
testcase_18 AC 420 ms
18,064 KB
testcase_19 AC 283 ms
14,624 KB
testcase_20 AC 190 ms
12,256 KB
testcase_21 AC 460 ms
19,444 KB
testcase_22 AC 1,443 ms
33,112 KB
testcase_23 AC 585 ms
17,428 KB
testcase_24 AC 409 ms
14,536 KB
testcase_25 AC 833 ms
22,176 KB
testcase_26 AC 411 ms
14,304 KB
testcase_27 AC 812 ms
21,652 KB
testcase_28 AC 1,251 ms
29,776 KB
testcase_29 AC 1,384 ms
32,080 KB
testcase_30 AC 92 ms
9,328 KB
testcase_31 AC 1,645 ms
35,484 KB
testcase_32 AC 15 ms
8,056 KB
testcase_33 AC 16 ms
8,204 KB
testcase_34 AC 17 ms
8,012 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