結果

問題 No.1606 Stuffed Animals Keeper
ユーザー roarisroaris
提出日時 2021-07-16 23:24:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,011 ms / 3,000 ms
コード長 698 bytes
コンパイル時間 271 ms
コンパイル使用メモリ 87,060 KB
実行使用メモリ 100,728 KB
最終ジャッジ日時 2023-09-20 15:56:13
合計ジャッジ時間 19,119 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,228 KB
testcase_01 AC 72 ms
70,900 KB
testcase_02 AC 72 ms
70,896 KB
testcase_03 AC 640 ms
91,056 KB
testcase_04 AC 750 ms
94,220 KB
testcase_05 AC 243 ms
81,200 KB
testcase_06 AC 342 ms
83,956 KB
testcase_07 AC 547 ms
89,368 KB
testcase_08 AC 491 ms
88,188 KB
testcase_09 AC 276 ms
82,540 KB
testcase_10 AC 215 ms
80,312 KB
testcase_11 AC 156 ms
78,684 KB
testcase_12 AC 333 ms
83,300 KB
testcase_13 AC 85 ms
76,484 KB
testcase_14 AC 75 ms
76,032 KB
testcase_15 AC 95 ms
77,912 KB
testcase_16 AC 864 ms
99,824 KB
testcase_17 AC 861 ms
99,796 KB
testcase_18 AC 961 ms
100,508 KB
testcase_19 AC 973 ms
99,832 KB
testcase_20 AC 1,011 ms
99,940 KB
testcase_21 AC 257 ms
81,888 KB
testcase_22 AC 236 ms
81,260 KB
testcase_23 AC 240 ms
81,172 KB
testcase_24 AC 245 ms
81,512 KB
testcase_25 AC 239 ms
81,580 KB
testcase_26 AC 150 ms
78,496 KB
testcase_27 AC 152 ms
78,532 KB
testcase_28 AC 148 ms
78,316 KB
testcase_29 AC 155 ms
78,556 KB
testcase_30 AC 143 ms
78,168 KB
testcase_31 AC 134 ms
77,948 KB
testcase_32 AC 101 ms
77,380 KB
testcase_33 AC 127 ms
77,820 KB
testcase_34 AC 102 ms
77,412 KB
testcase_35 AC 125 ms
77,680 KB
testcase_36 AC 128 ms
78,076 KB
testcase_37 AC 121 ms
77,768 KB
testcase_38 AC 124 ms
77,640 KB
testcase_39 AC 102 ms
77,408 KB
testcase_40 AC 101 ms
77,392 KB
testcase_41 AC 96 ms
77,248 KB
testcase_42 AC 97 ms
77,260 KB
testcase_43 AC 944 ms
100,208 KB
testcase_44 AC 896 ms
99,844 KB
testcase_45 AC 860 ms
99,648 KB
testcase_46 AC 806 ms
99,268 KB
testcase_47 AC 901 ms
100,728 KB
testcase_48 AC 71 ms
71,456 KB
testcase_49 AC 70 ms
71,308 KB
testcase_50 AC 71 ms
71,232 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
l = []
niku, sou = 0, 0

for i in range(N):
    if A[i]==0:
        niku += 1
    elif A[i]==1:
        sou += 1
    else:
        l.append((niku, sou))
        niku, sou = 0, 0

l.append((niku, sou))
niku_S = A.count(0)
dp = [[10**18]*(niku_S+1) for _ in range(len(l)+1)]
dp[0][0] = 0

for i in range(len(l)):
    for j in range(niku_S+1):
        dp[i+1][j] = min(dp[i+1][j], dp[i][j]+l[i][0])
        
        if j+sum(l[i])<=niku_S:
            dp[i+1][j+sum(l[i])] = min(dp[i+1][j+sum(l[i])], dp[i][j]+l[i][1])

if dp[-1][-1]==10**18:
    print(-1)
else:
    ans = dp[len(l)][niku_S]//2
    print(ans)
0