結果

問題 No.1606 Stuffed Animals Keeper
ユーザー ああいいああいい
提出日時 2022-03-07 11:59:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 186 ms / 3,000 ms
コード長 712 bytes
コンパイル時間 310 ms
コンパイル使用メモリ 87,084 KB
実行使用メモリ 99,840 KB
最終ジャッジ日時 2023-09-29 11:17:31
合計ジャッジ時間 9,264 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,280 KB
testcase_01 AC 73 ms
71,060 KB
testcase_02 AC 77 ms
71,448 KB
testcase_03 AC 141 ms
86,296 KB
testcase_04 AC 151 ms
86,632 KB
testcase_05 AC 103 ms
76,292 KB
testcase_06 AC 107 ms
76,500 KB
testcase_07 AC 132 ms
85,076 KB
testcase_08 AC 130 ms
84,008 KB
testcase_09 AC 104 ms
76,308 KB
testcase_10 AC 96 ms
76,144 KB
testcase_11 AC 93 ms
76,124 KB
testcase_12 AC 109 ms
76,500 KB
testcase_13 AC 81 ms
75,988 KB
testcase_14 AC 78 ms
76,080 KB
testcase_15 AC 81 ms
75,896 KB
testcase_16 AC 159 ms
86,388 KB
testcase_17 AC 158 ms
86,376 KB
testcase_18 AC 160 ms
86,408 KB
testcase_19 AC 157 ms
86,484 KB
testcase_20 AC 156 ms
86,192 KB
testcase_21 AC 108 ms
76,148 KB
testcase_22 AC 108 ms
76,152 KB
testcase_23 AC 103 ms
76,436 KB
testcase_24 AC 106 ms
76,528 KB
testcase_25 AC 106 ms
76,376 KB
testcase_26 AC 99 ms
76,212 KB
testcase_27 AC 99 ms
76,344 KB
testcase_28 AC 99 ms
76,216 KB
testcase_29 AC 100 ms
76,128 KB
testcase_30 AC 98 ms
76,128 KB
testcase_31 AC 96 ms
76,128 KB
testcase_32 AC 89 ms
76,096 KB
testcase_33 AC 94 ms
76,180 KB
testcase_34 AC 89 ms
76,300 KB
testcase_35 AC 94 ms
76,228 KB
testcase_36 AC 95 ms
76,148 KB
testcase_37 AC 93 ms
76,516 KB
testcase_38 AC 101 ms
76,008 KB
testcase_39 AC 90 ms
76,036 KB
testcase_40 AC 95 ms
76,276 KB
testcase_41 AC 87 ms
76,088 KB
testcase_42 AC 88 ms
76,368 KB
testcase_43 AC 165 ms
86,368 KB
testcase_44 AC 164 ms
86,296 KB
testcase_45 AC 166 ms
86,636 KB
testcase_46 AC 167 ms
86,488 KB
testcase_47 AC 186 ms
99,840 KB
testcase_48 AC 75 ms
71,140 KB
testcase_49 AC 76 ms
70,964 KB
testcase_50 AC 76 ms
71,096 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
A = list(map(int,input().split()))
A.insert(0,2)
A.append(2)
N += 2
l = []
left = 0
S = 0
while left < N:
    right = left + 1
    count = 0
    while right < N and A[right] != 2:
        if A[right] == 0:
            count += 1
        right += 1
    if right - left > 1:
        l.append((right- left - 1,right - left - 1 - count))
    S += count
    left = right
n = len(l)
inf = 10 ** 6
dp = [[inf] * (S+1) for _ in range(n+1)]
dp[0][0] = 0
for i in range(n):
    w,v = l[i]
    for j in range(S+1):
        dp[i+1][j] = min(dp[i+1][j],dp[i][j])
        if j + w <= S:
            dp[i+1][j+w] = min(dp[i+1][j+w],dp[i][j] + v)
if dp[-1][-1] == inf:
    print(-1)
else:
    print(dp[-1][-1])
0