結果

問題 No.1606 Stuffed Animals Keeper
ユーザー KudeKude
提出日時 2021-07-16 23:26:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 165 ms / 3,000 ms
コード長 640 bytes
コンパイル時間 283 ms
コンパイル使用メモリ 87,184 KB
実行使用メモリ 78,420 KB
最終ジャッジ日時 2023-09-20 15:58:25
合計ジャッジ時間 8,037 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,380 KB
testcase_01 AC 75 ms
71,320 KB
testcase_02 AC 81 ms
71,428 KB
testcase_03 AC 147 ms
77,852 KB
testcase_04 AC 137 ms
77,864 KB
testcase_05 AC 99 ms
77,368 KB
testcase_06 AC 105 ms
77,304 KB
testcase_07 AC 123 ms
77,384 KB
testcase_08 AC 119 ms
77,396 KB
testcase_09 AC 101 ms
77,316 KB
testcase_10 AC 95 ms
77,360 KB
testcase_11 AC 89 ms
76,832 KB
testcase_12 AC 106 ms
77,528 KB
testcase_13 AC 78 ms
76,176 KB
testcase_14 AC 79 ms
76,208 KB
testcase_15 AC 79 ms
76,048 KB
testcase_16 AC 154 ms
77,900 KB
testcase_17 AC 155 ms
78,124 KB
testcase_18 AC 163 ms
77,920 KB
testcase_19 AC 150 ms
77,916 KB
testcase_20 AC 157 ms
77,948 KB
testcase_21 AC 99 ms
77,024 KB
testcase_22 AC 99 ms
77,140 KB
testcase_23 AC 99 ms
77,388 KB
testcase_24 AC 100 ms
77,172 KB
testcase_25 AC 99 ms
77,304 KB
testcase_26 AC 89 ms
76,460 KB
testcase_27 AC 88 ms
76,640 KB
testcase_28 AC 87 ms
76,624 KB
testcase_29 AC 86 ms
76,272 KB
testcase_30 AC 86 ms
76,512 KB
testcase_31 AC 86 ms
76,468 KB
testcase_32 AC 81 ms
76,172 KB
testcase_33 AC 84 ms
76,420 KB
testcase_34 AC 84 ms
76,476 KB
testcase_35 AC 86 ms
76,600 KB
testcase_36 AC 86 ms
76,584 KB
testcase_37 AC 87 ms
76,220 KB
testcase_38 AC 86 ms
76,556 KB
testcase_39 AC 83 ms
76,588 KB
testcase_40 AC 83 ms
76,224 KB
testcase_41 AC 85 ms
76,492 KB
testcase_42 AC 80 ms
76,420 KB
testcase_43 AC 163 ms
78,256 KB
testcase_44 AC 164 ms
78,224 KB
testcase_45 AC 165 ms
78,420 KB
testcase_46 AC 164 ms
78,208 KB
testcase_47 AC 163 ms
78,260 KB
testcase_48 AC 73 ms
71,492 KB
testcase_49 AC 74 ms
71,528 KB
testcase_50 AC 73 ms
71,064 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
a = list(map(int, input().split()))
a.append(2)
b = []
c0 = c1 = 0
for x in a:
    if x == 0:
        c0 += 1
    elif x == 1:
        c1 += 1
    else:
        if c0 or c1:
            b.append((c0, c1))
            c0 = c1 = 0
INF = 10 ** 9
dp = [INF] * (2 * n + 10)
B = n + 5
dp[B] = 0
for c0, c1 in b:
    ndp = [INF] * (2 * n + 10)
    for i in range(-n, n):
        if dp[B + i] == INF:
            continue
        ndp[B + i + c1] = min(ndp[B + i + c1], dp[B + i] + c1)
        ndp[B + i - c0] = min(ndp[B + i - c0], dp[B + i] + c0)
    dp = ndp
ans = dp[B]
if ans == INF:
    ans = -1
else:
    ans //= 2
print(ans)
0