結果

問題 No.1872 Dictionary Order
ユーザー tktk_snsntktk_snsn
提出日時 2022-03-11 23:02:20
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,086 bytes
コンパイル時間 357 ms
コンパイル使用メモリ 87,288 KB
実行使用メモリ 109,312 KB
最終ジャッジ日時 2023-10-14 08:16:58
合計ジャッジ時間 7,189 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 251 ms
109,312 KB
testcase_01 AC 83 ms
76,220 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 111 ms
76,496 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 108 ms
77,040 KB
testcase_21 AC 146 ms
88,684 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 82 ms
76,160 KB
testcase_31 WA -
testcase_32 AC 73 ms
71,260 KB
testcase_33 AC 74 ms
71,516 KB
testcase_34 AC 82 ms
76,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

dp = [[0] * (M + 1) for _ in range(N + 1)]
dp[0][0] = 1
for i, a in enumerate(A, 1):
    for j in range(M+1):
        dp[i][j] |= dp[i-1][j]  # 使わない
    for j in range(a, M+1):
        dp[i][j] |= dp[i-1][j-a]

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

# print(*dp, sep="\n")
# print()

dp[N][M] = 2
for i in reversed(range(N)):
    for j in range(M+1):
        if dp[i+1][j] == 2 and dp[i][j]:
            dp[i][j] = 2
    for j in range(A[i], M+1):
        if dp[i+1][j] == 2 and dp[i][j-A[i]]:
            dp[i][j-A[i]] = 2

ans = []
total = 0
now = 0

while True:
    pmin = 100000000
    tmp = -1
    for i in range(now, N):
        if dp[i][total] == 2:
            if total + A[i] > M:
                continue
            if dp[i+1][total + A[i]] == 2:
                if P[i] < pmin:
                    pmin = P[i]
                    tmp = i
    total += A[tmp]
    now = tmp
    ans.append(now+1)
    if total >= M:
        break

print(len(ans))
print(*ans)
0