結果

問題 No.1872 Dictionary Order
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2022-03-11 23:03:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 797 ms / 2,000 ms
コード長 1,303 bytes
コンパイル時間 239 ms
コンパイル使用メモリ 81,704 KB
実行使用メモリ 313,064 KB
最終ジャッジ日時 2023-10-19 12:38:36
合計ジャッジ時間 9,358 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 797 ms
313,064 KB
testcase_01 AC 55 ms
63,928 KB
testcase_02 AC 245 ms
92,100 KB
testcase_03 AC 96 ms
78,072 KB
testcase_04 AC 347 ms
100,504 KB
testcase_05 AC 68 ms
70,124 KB
testcase_06 AC 192 ms
86,816 KB
testcase_07 AC 139 ms
81,244 KB
testcase_08 AC 58 ms
66,276 KB
testcase_09 AC 112 ms
79,988 KB
testcase_10 AC 156 ms
83,816 KB
testcase_11 AC 244 ms
90,732 KB
testcase_12 AC 98 ms
78,636 KB
testcase_13 AC 106 ms
79,232 KB
testcase_14 AC 230 ms
90,088 KB
testcase_15 AC 266 ms
93,176 KB
testcase_16 AC 70 ms
72,596 KB
testcase_17 AC 167 ms
83,820 KB
testcase_18 AC 183 ms
86,396 KB
testcase_19 AC 149 ms
82,652 KB
testcase_20 AC 118 ms
79,988 KB
testcase_21 AC 203 ms
87,552 KB
testcase_22 AC 459 ms
102,468 KB
testcase_23 AC 194 ms
86,140 KB
testcase_24 AC 139 ms
82,596 KB
testcase_25 AC 270 ms
90,760 KB
testcase_26 AC 135 ms
82,428 KB
testcase_27 AC 267 ms
90,232 KB
testcase_28 AC 406 ms
98,484 KB
testcase_29 AC 438 ms
101,380 KB
testcase_30 AC 59 ms
66,004 KB
testcase_31 AC 496 ms
104,976 KB
testcase_32 AC 39 ms
53,364 KB
testcase_33 AC 39 ms
53,364 KB
testcase_34 AC 48 ms
61,816 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

"""

本当に酷い
ちゃんと推移を考えないからです

dp[v][S]
= v以降から和がSの集合を取る事が達成できる場合
 最初に取ることができる要素の (P_i,A_i,i)

"""

import sys
from sys import stdin

N,M = map(int,stdin.readline().split())
a = A = list(map(int,stdin.readline().split()))
P = list(map(int,stdin.readline().split()))

for i in range(N):
    P[i] -= 1

dp = [ [False] * (M+1) for i in range(N+1) ]
dp[N][0] = True

for i in range(N,0,-1):

    for j in range(M+1):

        # i-1 番目を取らない場合
        
        if dp[i][j] == False:
            continue

        if dp[i-1][j] == False or dp[i][j] == True:
            dp[i-1][j] = dp[i][j]
        else:
            dp[i-1][j] = min(dp[i-1][j] , dp[i][j])

        #取る場合
        nexj = j + a[i-1]
        if nexj > M:
            continue

        tup = (P[i-1],A[i-1],i)
        
        if dp[i-1][nexj] == False or dp[i][j] == True:
            dp[i-1][nexj] = tup
        else:
            dp[i-1][nexj] = min(dp[i-1][nexj] , tup)

ntup = dp[0][M]
if ntup == False:
    print (-1)
    sys.exit()

ANS = ans = []
NM = M

while NM > 0:

    ans.append( ntup[2] )

    NV = ntup[2]
    NM -= ntup[1]
    ntup = dp[NV][NM]

print (len(ans))
print (" ".join(map(str,ANS)))
0