結果

問題 No.1606 Stuffed Animals Keeper
ユーザー NoneNone
提出日時 2021-10-04 04:51:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 126 ms / 3,000 ms
コード長 475 bytes
コンパイル時間 381 ms
コンパイル使用メモリ 87,320 KB
実行使用メモリ 76,884 KB
最終ジャッジ日時 2023-09-29 08:37:22
合計ジャッジ時間 8,048 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,124 KB
testcase_01 AC 74 ms
71,076 KB
testcase_02 AC 76 ms
71,288 KB
testcase_03 AC 113 ms
76,640 KB
testcase_04 AC 116 ms
76,360 KB
testcase_05 AC 93 ms
76,356 KB
testcase_06 AC 98 ms
76,604 KB
testcase_07 AC 108 ms
76,844 KB
testcase_08 AC 106 ms
76,640 KB
testcase_09 AC 95 ms
76,852 KB
testcase_10 AC 94 ms
76,644 KB
testcase_11 AC 88 ms
76,540 KB
testcase_12 AC 101 ms
76,884 KB
testcase_13 AC 81 ms
76,448 KB
testcase_14 AC 78 ms
76,268 KB
testcase_15 AC 85 ms
76,536 KB
testcase_16 AC 126 ms
76,736 KB
testcase_17 AC 124 ms
76,660 KB
testcase_18 AC 123 ms
76,584 KB
testcase_19 AC 122 ms
76,668 KB
testcase_20 AC 122 ms
76,656 KB
testcase_21 AC 95 ms
76,640 KB
testcase_22 AC 95 ms
76,192 KB
testcase_23 AC 100 ms
76,564 KB
testcase_24 AC 100 ms
76,472 KB
testcase_25 AC 96 ms
76,520 KB
testcase_26 AC 95 ms
76,536 KB
testcase_27 AC 94 ms
76,428 KB
testcase_28 AC 94 ms
76,208 KB
testcase_29 AC 94 ms
76,544 KB
testcase_30 AC 94 ms
76,364 KB
testcase_31 AC 92 ms
76,180 KB
testcase_32 AC 87 ms
76,608 KB
testcase_33 AC 93 ms
76,520 KB
testcase_34 AC 86 ms
76,136 KB
testcase_35 AC 90 ms
76,616 KB
testcase_36 AC 93 ms
76,420 KB
testcase_37 AC 93 ms
76,548 KB
testcase_38 AC 89 ms
76,412 KB
testcase_39 AC 85 ms
76,412 KB
testcase_40 AC 86 ms
76,368 KB
testcase_41 AC 83 ms
76,384 KB
testcase_42 AC 86 ms
76,448 KB
testcase_43 AC 116 ms
76,616 KB
testcase_44 AC 114 ms
76,624 KB
testcase_45 AC 116 ms
76,856 KB
testcase_46 AC 116 ms
76,600 KB
testcase_47 AC 113 ms
76,860 KB
testcase_48 AC 73 ms
71,404 KB
testcase_49 AC 73 ms
71,428 KB
testcase_50 AC 73 ms
71,180 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())
A=list(map(int, input().split()))
A0,A1=[0],[0]
for a in A:
    if a==0:
        A0[-1]+=1
    elif a==1:
        A1[-1]+=1
    else:
        A0.append(0)
        A1.append(0)
C0=sum(A0)
INF=10**9
dp=[INF]*(C0+1)
dp[0]=0
for a0,a1 in zip(A0,A1):
    for c in range(C0+1)[::-1]:
        if c-(a0+a1)>=0 and dp[c-(a0+a1)]<INF:
            dp[c]=min(dp[c-(a0+a1)]+a1,dp[c]+a0)
        elif dp[c]<INF:
            dp[c]+=a0


print(dp[-1]//2 if dp[-1]<INF else -1)
0