結果

問題 No.1606 Stuffed Animals Keeper
ユーザー H3PO4H3PO4
提出日時 2021-07-16 22:16:32
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 566 bytes
コンパイル時間 91 ms
コンパイル使用メモリ 10,864 KB
実行使用メモリ 30,008 KB
最終ジャッジ日時 2023-09-20 14:25:53
合計ジャッジ時間 10,979 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 137 ms
29,680 KB
testcase_01 AC 137 ms
29,668 KB
testcase_02 AC 138 ms
29,636 KB
testcase_03 AC 150 ms
29,728 KB
testcase_04 AC 152 ms
29,832 KB
testcase_05 AC 138 ms
29,612 KB
testcase_06 AC 140 ms
29,620 KB
testcase_07 AC 143 ms
29,780 KB
testcase_08 AC 144 ms
29,768 KB
testcase_09 AC 139 ms
29,764 KB
testcase_10 AC 139 ms
29,764 KB
testcase_11 AC 136 ms
29,684 KB
testcase_12 AC 142 ms
29,708 KB
testcase_13 RE -
testcase_14 AC 141 ms
29,724 KB
testcase_15 AC 139 ms
29,692 KB
testcase_16 AC 152 ms
29,864 KB
testcase_17 AC 153 ms
29,872 KB
testcase_18 AC 152 ms
29,816 KB
testcase_19 AC 153 ms
29,864 KB
testcase_20 AC 153 ms
29,912 KB
testcase_21 AC 145 ms
29,868 KB
testcase_22 AC 142 ms
29,864 KB
testcase_23 AC 146 ms
30,008 KB
testcase_24 AC 146 ms
29,772 KB
testcase_25 AC 146 ms
29,864 KB
testcase_26 AC 144 ms
29,868 KB
testcase_27 AC 143 ms
29,836 KB
testcase_28 AC 142 ms
29,776 KB
testcase_29 AC 143 ms
29,720 KB
testcase_30 AC 142 ms
29,868 KB
testcase_31 AC 141 ms
29,804 KB
testcase_32 AC 138 ms
29,860 KB
testcase_33 AC 138 ms
29,868 KB
testcase_34 AC 137 ms
29,976 KB
testcase_35 AC 139 ms
29,772 KB
testcase_36 AC 138 ms
29,856 KB
testcase_37 AC 139 ms
29,892 KB
testcase_38 AC 139 ms
29,888 KB
testcase_39 AC 139 ms
29,932 KB
testcase_40 AC 141 ms
29,860 KB
testcase_41 AC 140 ms
29,856 KB
testcase_42 AC 140 ms
29,784 KB
testcase_43 AC 161 ms
29,960 KB
testcase_44 AC 162 ms
29,816 KB
testcase_45 AC 161 ms
29,940 KB
testcase_46 AC 162 ms
29,940 KB
testcase_47 AC 162 ms
29,824 KB
testcase_48 AC 139 ms
29,636 KB
testcase_49 AC 137 ms
29,696 KB
testcase_50 AC 138 ms
29,544 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np

N = int(input())
A = tuple(map(int, input().split()))
INF = 10000

c, h = 0, 0  # 肉食, 草食
dp = np.full(N, INF)
dp[0] = 0
for i in range(N + 1):
    if i == N or A[i] == 2:
        if c == h == 0:
            continue
        new_dp = dp + c  # 草食に揃える
        new_dp[c + h:] = np.minimum(new_dp[c + h:], dp[:-c - h] + h)  # 肉食に揃える
        dp = new_dp
        c, h = 0, 0
    elif A[i] == 0:
        c += 1
    elif A[i] == 1:
        h += 1
res = dp[A.count(0)]
if res >= INF:
    print(-1)
else:
    print(res // 2)
0