結果

問題 No.1606 Stuffed Animals Keeper
ユーザー H3PO4H3PO4
提出日時 2021-07-16 22:22:21
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 165 ms / 3,000 ms
コード長 571 bytes
コンパイル時間 290 ms
コンパイル使用メモリ 10,768 KB
実行使用メモリ 29,996 KB
最終ジャッジ日時 2023-09-20 14:36:06
合計ジャッジ時間 9,960 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 142 ms
29,760 KB
testcase_01 AC 135 ms
29,796 KB
testcase_02 AC 140 ms
29,804 KB
testcase_03 AC 150 ms
29,952 KB
testcase_04 AC 150 ms
29,852 KB
testcase_05 AC 142 ms
29,836 KB
testcase_06 AC 144 ms
29,700 KB
testcase_07 AC 149 ms
29,848 KB
testcase_08 AC 142 ms
29,876 KB
testcase_09 AC 140 ms
29,852 KB
testcase_10 AC 139 ms
29,716 KB
testcase_11 AC 142 ms
29,740 KB
testcase_12 AC 145 ms
29,852 KB
testcase_13 AC 138 ms
29,740 KB
testcase_14 AC 136 ms
29,888 KB
testcase_15 AC 138 ms
29,848 KB
testcase_16 AC 157 ms
29,908 KB
testcase_17 AC 157 ms
29,952 KB
testcase_18 AC 153 ms
29,928 KB
testcase_19 AC 155 ms
29,916 KB
testcase_20 AC 158 ms
29,824 KB
testcase_21 AC 145 ms
29,996 KB
testcase_22 AC 142 ms
29,944 KB
testcase_23 AC 144 ms
29,984 KB
testcase_24 AC 142 ms
29,996 KB
testcase_25 AC 143 ms
29,988 KB
testcase_26 AC 141 ms
29,988 KB
testcase_27 AC 142 ms
29,812 KB
testcase_28 AC 138 ms
29,988 KB
testcase_29 AC 143 ms
29,852 KB
testcase_30 AC 144 ms
29,948 KB
testcase_31 AC 138 ms
29,900 KB
testcase_32 AC 140 ms
29,908 KB
testcase_33 AC 137 ms
29,944 KB
testcase_34 AC 141 ms
29,980 KB
testcase_35 AC 142 ms
29,800 KB
testcase_36 AC 137 ms
29,912 KB
testcase_37 AC 139 ms
29,864 KB
testcase_38 AC 138 ms
29,972 KB
testcase_39 AC 141 ms
29,992 KB
testcase_40 AC 137 ms
29,984 KB
testcase_41 AC 137 ms
29,872 KB
testcase_42 AC 139 ms
29,736 KB
testcase_43 AC 162 ms
29,988 KB
testcase_44 AC 163 ms
29,752 KB
testcase_45 AC 165 ms
29,952 KB
testcase_46 AC 162 ms
29,912 KB
testcase_47 AC 162 ms
29,900 KB
testcase_48 AC 138 ms
29,796 KB
testcase_49 AC 134 ms
29,604 KB
testcase_50 AC 139 ms
29,588 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 + 1, 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