結果

問題 No.1606 Stuffed Animals Keeper
ユーザー convexineqconvexineq
提出日時 2021-07-16 22:06:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 330 ms / 3,000 ms
コード長 537 bytes
コンパイル時間 299 ms
コンパイル使用メモリ 86,612 KB
実行使用メモリ 81,352 KB
最終ジャッジ日時 2023-09-20 14:08:22
合計ジャッジ時間 11,218 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
71,620 KB
testcase_01 AC 96 ms
71,728 KB
testcase_02 AC 98 ms
71,620 KB
testcase_03 AC 244 ms
79,092 KB
testcase_04 AC 287 ms
79,840 KB
testcase_05 AC 148 ms
78,548 KB
testcase_06 AC 180 ms
78,988 KB
testcase_07 AC 244 ms
79,068 KB
testcase_08 AC 217 ms
78,720 KB
testcase_09 AC 169 ms
78,856 KB
testcase_10 AC 146 ms
78,452 KB
testcase_11 AC 129 ms
78,300 KB
testcase_12 AC 179 ms
79,200 KB
testcase_13 AC 100 ms
77,092 KB
testcase_14 AC 101 ms
77,088 KB
testcase_15 AC 99 ms
77,204 KB
testcase_16 AC 318 ms
80,924 KB
testcase_17 AC 317 ms
81,352 KB
testcase_18 AC 324 ms
80,916 KB
testcase_19 AC 330 ms
80,860 KB
testcase_20 AC 323 ms
81,328 KB
testcase_21 AC 187 ms
79,200 KB
testcase_22 AC 178 ms
79,464 KB
testcase_23 AC 181 ms
78,680 KB
testcase_24 AC 183 ms
79,288 KB
testcase_25 AC 175 ms
79,140 KB
testcase_26 AC 145 ms
78,580 KB
testcase_27 AC 152 ms
78,780 KB
testcase_28 AC 145 ms
78,972 KB
testcase_29 AC 150 ms
78,932 KB
testcase_30 AC 144 ms
78,848 KB
testcase_31 AC 145 ms
78,860 KB
testcase_32 AC 104 ms
77,336 KB
testcase_33 AC 137 ms
78,972 KB
testcase_34 AC 102 ms
77,580 KB
testcase_35 AC 141 ms
79,080 KB
testcase_36 AC 137 ms
79,060 KB
testcase_37 AC 138 ms
78,960 KB
testcase_38 AC 132 ms
78,020 KB
testcase_39 AC 103 ms
77,408 KB
testcase_40 AC 105 ms
77,404 KB
testcase_41 AC 104 ms
77,340 KB
testcase_42 AC 103 ms
77,304 KB
testcase_43 AC 267 ms
79,756 KB
testcase_44 AC 272 ms
79,444 KB
testcase_45 AC 260 ms
79,792 KB
testcase_46 AC 265 ms
79,740 KB
testcase_47 AC 259 ms
79,672 KB
testcase_48 AC 92 ms
71,476 KB
testcase_49 AC 93 ms
71,476 KB
testcase_50 AC 92 ms
71,600 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
*a, = map(int,input().split())
a.append(2)
res = []
c = d = 0
for ai in a:
    if ai == 0:
        c += 1
    elif ai == 1:
        d += 1
    else:
        if c or d:
            res.append((c,d))
        c = d = 0
dp = {0:0} # 差が k になる最小回数が v
from collections import defaultdict
for c,d in res:
    ndp = defaultdict(lambda :100000)
    for k,v in dp.items():
        ndp[k+c] = min(ndp[k+c],v+c)
        ndp[k-d] = min(ndp[k-d],v+d)
    dp = ndp
if 0 in dp:
    print(dp[0]//2)
else:
    print(-1)
0