結果

問題 No.1606 Stuffed Animals Keeper
ユーザー KudeKude
提出日時 2021-07-16 22:09:47
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 641 bytes
コンパイル時間 379 ms
コンパイル使用メモリ 87,280 KB
実行使用メモリ 80,284 KB
最終ジャッジ日時 2023-09-20 14:13:18
合計ジャッジ時間 8,130 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,288 KB
testcase_01 AC 75 ms
71,408 KB
testcase_02 AC 75 ms
71,312 KB
testcase_03 AC 135 ms
77,708 KB
testcase_04 AC 142 ms
77,808 KB
testcase_05 AC 102 ms
77,408 KB
testcase_06 AC 112 ms
77,464 KB
testcase_07 AC 130 ms
77,528 KB
testcase_08 AC 121 ms
77,540 KB
testcase_09 AC 107 ms
77,344 KB
testcase_10 AC 99 ms
77,536 KB
testcase_11 AC 92 ms
77,008 KB
testcase_12 AC 110 ms
77,544 KB
testcase_13 AC 80 ms
76,480 KB
testcase_14 AC 82 ms
76,400 KB
testcase_15 RE -
testcase_16 AC 153 ms
78,036 KB
testcase_17 AC 157 ms
78,276 KB
testcase_18 AC 166 ms
78,032 KB
testcase_19 AC 157 ms
78,220 KB
testcase_20 AC 159 ms
78,052 KB
testcase_21 AC 104 ms
77,276 KB
testcase_22 AC 104 ms
77,272 KB
testcase_23 AC 102 ms
77,336 KB
testcase_24 AC 105 ms
77,512 KB
testcase_25 AC 104 ms
77,084 KB
testcase_26 AC 93 ms
76,444 KB
testcase_27 AC 93 ms
76,436 KB
testcase_28 AC 92 ms
76,628 KB
testcase_29 AC 93 ms
76,552 KB
testcase_30 AC 93 ms
76,600 KB
testcase_31 AC 90 ms
76,416 KB
testcase_32 AC 85 ms
76,592 KB
testcase_33 AC 88 ms
76,692 KB
testcase_34 AC 89 ms
76,640 KB
testcase_35 AC 90 ms
76,616 KB
testcase_36 AC 90 ms
76,580 KB
testcase_37 AC 90 ms
76,640 KB
testcase_38 AC 89 ms
76,752 KB
testcase_39 AC 91 ms
76,628 KB
testcase_40 AC 87 ms
76,568 KB
testcase_41 AC 85 ms
76,564 KB
testcase_42 AC 84 ms
76,456 KB
testcase_43 AC 167 ms
78,340 KB
testcase_44 AC 168 ms
78,344 KB
testcase_45 AC 172 ms
78,292 KB
testcase_46 AC 168 ms
78,692 KB
testcase_47 AC 169 ms
78,432 KB
testcase_48 AC 77 ms
71,372 KB
testcase_49 AC 78 ms
71,612 KB
testcase_50 RE -
権限があれば一括ダウンロードができます

ソースコード

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 = ndp[B]
if ans == INF:
    ans = -1
else:
    ans //= 2
print(ans)
0