結果

問題 No.1606 Stuffed Animals Keeper
ユーザー titiatitia
提出日時 2021-07-17 18:57:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 142 ms / 3,000 ms
コード長 618 bytes
コンパイル時間 291 ms
コンパイル使用メモリ 87,048 KB
実行使用メモリ 78,044 KB
最終ジャッジ日時 2023-09-21 12:14:32
合計ジャッジ時間 7,516 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
75,768 KB
testcase_01 AC 70 ms
75,780 KB
testcase_02 AC 70 ms
75,848 KB
testcase_03 AC 116 ms
77,500 KB
testcase_04 AC 122 ms
77,736 KB
testcase_05 AC 95 ms
77,452 KB
testcase_06 AC 102 ms
77,700 KB
testcase_07 AC 113 ms
77,700 KB
testcase_08 AC 111 ms
77,748 KB
testcase_09 AC 97 ms
77,544 KB
testcase_10 AC 91 ms
77,500 KB
testcase_11 AC 86 ms
77,548 KB
testcase_12 AC 102 ms
77,628 KB
testcase_13 AC 71 ms
76,428 KB
testcase_14 AC 72 ms
76,404 KB
testcase_15 AC 72 ms
76,372 KB
testcase_16 AC 132 ms
77,596 KB
testcase_17 AC 128 ms
77,952 KB
testcase_18 AC 131 ms
77,720 KB
testcase_19 AC 133 ms
77,728 KB
testcase_20 AC 130 ms
77,696 KB
testcase_21 AC 89 ms
76,632 KB
testcase_22 AC 88 ms
76,712 KB
testcase_23 AC 90 ms
76,600 KB
testcase_24 AC 90 ms
76,740 KB
testcase_25 AC 88 ms
76,724 KB
testcase_26 AC 80 ms
76,628 KB
testcase_27 AC 81 ms
76,692 KB
testcase_28 AC 81 ms
76,816 KB
testcase_29 AC 82 ms
76,428 KB
testcase_30 AC 79 ms
76,688 KB
testcase_31 AC 80 ms
76,652 KB
testcase_32 AC 75 ms
76,624 KB
testcase_33 AC 78 ms
76,684 KB
testcase_34 AC 76 ms
76,572 KB
testcase_35 AC 81 ms
76,696 KB
testcase_36 AC 79 ms
76,632 KB
testcase_37 AC 79 ms
76,700 KB
testcase_38 AC 78 ms
76,656 KB
testcase_39 AC 77 ms
76,768 KB
testcase_40 AC 77 ms
76,552 KB
testcase_41 AC 73 ms
76,600 KB
testcase_42 AC 73 ms
76,316 KB
testcase_43 AC 142 ms
77,864 KB
testcase_44 AC 130 ms
78,044 KB
testcase_45 AC 133 ms
77,840 KB
testcase_46 AC 131 ms
77,740 KB
testcase_47 AC 129 ms
77,904 KB
testcase_48 AC 69 ms
75,828 KB
testcase_49 AC 69 ms
75,832 KB
testcase_50 AC 66 ms
71,572 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

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

X=[[0,0]]

for a in A:
    if a==0:
        X[-1][0]+=1
    elif a==1:
        X[-1][1]+=1
    else:
        X.append([0,0])

Y=[]
zeros=0
for x,y in X:
    if x==0 and y==0:
        continue
    zeros+=x
    Y.append([x,y])

DP=[1<<32]*5001
DP[0]=0

for x,y in Y:
    NDP=[1<<32]*5001
    
    for i in range(5000,-1,-1):
        if DP[i]==1<<32:
            continue
        NDP[i+x+y]=min(NDP[i+x+y],DP[i]+y)
        NDP[i]=min(NDP[i],DP[i]+x)

    DP=NDP

if DP[zeros]==1<<32:
    print(-1)
else:
    print(DP[zeros]//2)
    
0