結果

問題 No.1606 Stuffed Animals Keeper
ユーザー 👑 H20H20
提出日時 2023-06-15 12:54:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 561 ms / 3,000 ms
コード長 736 bytes
コンパイル時間 369 ms
コンパイル使用メモリ 87,208 KB
実行使用メモリ 83,760 KB
最終ジャッジ日時 2023-09-05 18:04:52
合計ジャッジ時間 15,325 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
71,696 KB
testcase_01 AC 91 ms
71,888 KB
testcase_02 AC 95 ms
71,432 KB
testcase_03 AC 408 ms
82,120 KB
testcase_04 AC 486 ms
82,440 KB
testcase_05 AC 225 ms
79,628 KB
testcase_06 AC 274 ms
79,912 KB
testcase_07 AC 382 ms
81,688 KB
testcase_08 AC 356 ms
80,928 KB
testcase_09 AC 239 ms
79,700 KB
testcase_10 AC 193 ms
79,060 KB
testcase_11 AC 165 ms
79,052 KB
testcase_12 AC 263 ms
80,136 KB
testcase_13 AC 96 ms
77,588 KB
testcase_14 AC 98 ms
77,636 KB
testcase_15 AC 98 ms
77,548 KB
testcase_16 AC 547 ms
82,768 KB
testcase_17 AC 549 ms
83,040 KB
testcase_18 AC 543 ms
83,392 KB
testcase_19 AC 561 ms
83,760 KB
testcase_20 AC 550 ms
83,544 KB
testcase_21 AC 275 ms
80,692 KB
testcase_22 AC 258 ms
81,076 KB
testcase_23 AC 272 ms
80,280 KB
testcase_24 AC 261 ms
80,600 KB
testcase_25 AC 271 ms
81,036 KB
testcase_26 AC 184 ms
79,716 KB
testcase_27 AC 186 ms
79,812 KB
testcase_28 AC 183 ms
79,376 KB
testcase_29 AC 188 ms
79,696 KB
testcase_30 AC 180 ms
79,496 KB
testcase_31 AC 171 ms
79,364 KB
testcase_32 AC 101 ms
77,664 KB
testcase_33 AC 168 ms
79,140 KB
testcase_34 AC 99 ms
77,864 KB
testcase_35 AC 170 ms
79,296 KB
testcase_36 AC 173 ms
79,588 KB
testcase_37 AC 163 ms
79,376 KB
testcase_38 AC 158 ms
79,488 KB
testcase_39 AC 100 ms
77,660 KB
testcase_40 AC 101 ms
77,880 KB
testcase_41 AC 103 ms
77,840 KB
testcase_42 AC 104 ms
77,716 KB
testcase_43 AC 423 ms
80,556 KB
testcase_44 AC 422 ms
80,348 KB
testcase_45 AC 421 ms
80,544 KB
testcase_46 AC 416 ms
80,620 KB
testcase_47 AC 427 ms
80,940 KB
testcase_48 AC 93 ms
71,796 KB
testcase_49 AC 90 ms
71,868 KB
testcase_50 AC 89 ms
71,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections
N = int(input())
A = list(map(int,input().split()))
ZERO = A.count(0)
ONE = A.count(1)
L = []
SEP = []
for a in A:
    if a==2:
        if len(SEP)>0:
            L.append(SEP)
            SEP = []
    else:
        SEP.append(a)
L.append(SEP)
#コストを設定
DP = collections.defaultdict(lambda:10**4)
DP[(0,0)]=0
for l in L:
    NDP = collections.defaultdict(lambda:10**4)
    CA = collections.Counter(l)
    for k,v in DP.items():
        z,o = k
        if z+len(l)<=ZERO:
            NDP[(z+len(l),o)]=min(NDP[(z+len(l),o)],v+CA[1])
        if o+len(l)<=ONE:
            NDP[(z,o+len(l))]=min(NDP[(z,o+len(l))],v+CA[0])
    DP = NDP
if DP[(ZERO,ONE)]==10**4:
    print(-1)
else:
    print(DP[(ZERO,ONE)]//2)
0