結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 AC 26 ms
8,424 KB
testcase_02 AC 592 ms
23,032 KB
testcase_03 AC 102 ms
10,384 KB
testcase_04 AC 932 ms
31,472 KB
testcase_05 AC 39 ms
8,776 KB
testcase_06 AC 419 ms
18,544 KB
testcase_07 AC 222 ms
13,544 KB
testcase_08 AC 18 ms
8,400 KB
testcase_09 AC 181 ms
12,352 KB
testcase_10 AC 307 ms
15,720 KB
testcase_11 AC 576 ms
22,296 KB
testcase_12 AC 124 ms
11,160 KB
testcase_13 AC 152 ms
11,632 KB
testcase_14 AC 537 ms
21,424 KB
testcase_15 AC 685 ms
24,884 KB
testcase_16 AC 38 ms
8,776 KB
testcase_17 AC 336 ms
16,276 KB
testcase_18 AC 394 ms
18,016 KB
testcase_19 AC 271 ms
14,612 KB
testcase_20 AC 178 ms
12,288 KB
testcase_21 AC 449 ms
19,340 KB
testcase_22 AC 1,370 ms
33,084 KB
testcase_23 AC 567 ms
17,596 KB
testcase_24 AC 393 ms
14,312 KB
testcase_25 AC 801 ms
22,232 KB
testcase_26 AC 405 ms
14,428 KB
testcase_27 AC 835 ms
21,724 KB
testcase_28 AC 1,195 ms
29,740 KB
testcase_29 AC 1,403 ms
32,184 KB
testcase_30 AC 85 ms
9,328 KB
testcase_31 AC 1,552 ms
35,520 KB
testcase_32 AC 16 ms
7,860 KB
testcase_33 AC 15 ms
8,264 KB
testcase_34 AC 16 ms
7,796 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]][now] 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