結果

問題 No.1606 Stuffed Animals Keeper
ユーザー 👑 rin204rin204
提出日時 2021-07-16 21:38:52
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 156 ms / 3,000 ms
コード長 543 bytes
コンパイル時間 269 ms
コンパイル使用メモリ 87,280 KB
実行使用メモリ 78,104 KB
最終ジャッジ日時 2023-09-20 13:20:34
合計ジャッジ時間 7,300 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,276 KB
testcase_01 AC 73 ms
71,064 KB
testcase_02 AC 74 ms
71,440 KB
testcase_03 AC 122 ms
77,380 KB
testcase_04 AC 123 ms
77,696 KB
testcase_05 AC 99 ms
76,876 KB
testcase_06 AC 100 ms
77,292 KB
testcase_07 AC 115 ms
77,756 KB
testcase_08 AC 110 ms
77,720 KB
testcase_09 AC 100 ms
77,512 KB
testcase_10 AC 93 ms
76,912 KB
testcase_11 AC 87 ms
76,792 KB
testcase_12 AC 101 ms
77,564 KB
testcase_13 AC 77 ms
76,128 KB
testcase_14 AC 79 ms
76,260 KB
testcase_15 AC 75 ms
76,104 KB
testcase_16 AC 128 ms
77,720 KB
testcase_17 AC 128 ms
77,784 KB
testcase_18 AC 128 ms
77,816 KB
testcase_19 AC 124 ms
77,672 KB
testcase_20 AC 127 ms
77,684 KB
testcase_21 AC 102 ms
77,492 KB
testcase_22 AC 102 ms
77,540 KB
testcase_23 AC 102 ms
77,508 KB
testcase_24 AC 102 ms
77,464 KB
testcase_25 AC 103 ms
77,532 KB
testcase_26 AC 95 ms
76,724 KB
testcase_27 AC 95 ms
76,512 KB
testcase_28 AC 95 ms
76,788 KB
testcase_29 AC 96 ms
76,732 KB
testcase_30 AC 97 ms
76,704 KB
testcase_31 AC 96 ms
76,820 KB
testcase_32 AC 86 ms
76,464 KB
testcase_33 AC 94 ms
76,712 KB
testcase_34 AC 87 ms
76,448 KB
testcase_35 AC 93 ms
76,640 KB
testcase_36 AC 95 ms
76,740 KB
testcase_37 AC 94 ms
76,796 KB
testcase_38 AC 93 ms
76,612 KB
testcase_39 AC 86 ms
76,660 KB
testcase_40 AC 84 ms
76,444 KB
testcase_41 AC 78 ms
76,436 KB
testcase_42 AC 88 ms
76,432 KB
testcase_43 AC 151 ms
77,872 KB
testcase_44 AC 152 ms
78,092 KB
testcase_45 AC 156 ms
77,968 KB
testcase_46 AC 152 ms
77,832 KB
testcase_47 AC 156 ms
78,104 KB
testcase_48 AC 73 ms
71,432 KB
testcase_49 AC 71 ms
71,484 KB
testcase_50 AC 73 ms
71,284 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
alst = list(map(int, input().split()))
one = 0
vw = []
tot = 0
cnt = 0
for a in alst:
    if a == 2:
        if tot != 0:
            vw.append((cnt, tot))
        cnt = tot = 0
    elif a == 0:
        tot += 1
    else:
        cnt += 1
        tot += 1
        one += 1
if tot != 0:
    vw.append((cnt, tot))
dp = [-10 ** 20 for _ in range(one + 1)]
dp[0] = 0
for v, w in vw:
    for j in range(one, w - 1, -1):
        dp[j] = max(dp[j], dp[j - w] + v)

if dp[one] < 0:
    print(-1)
else:
    print(one - dp[-1])
        
0