結果

問題 No.1606 Stuffed Animals Keeper
ユーザー KudeKude
提出日時 2021-07-16 22:14:31
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 645 bytes
コンパイル時間 287 ms
コンパイル使用メモリ 86,936 KB
実行使用メモリ 260,496 KB
最終ジャッジ日時 2023-09-20 14:22:39
合計ジャッジ時間 8,996 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,324 KB
testcase_01 AC 71 ms
71,396 KB
testcase_02 AC 72 ms
71,312 KB
testcase_03 AC 144 ms
78,660 KB
testcase_04 AC 229 ms
211,480 KB
testcase_05 AC 98 ms
77,508 KB
testcase_06 AC 109 ms
77,368 KB
testcase_07 AC 131 ms
78,136 KB
testcase_08 AC 123 ms
78,148 KB
testcase_09 AC 103 ms
77,360 KB
testcase_10 AC 95 ms
77,236 KB
testcase_11 AC 88 ms
76,492 KB
testcase_12 AC 107 ms
77,700 KB
testcase_13 AC 77 ms
76,320 KB
testcase_14 AC 78 ms
76,476 KB
testcase_15 RE -
testcase_16 AC 265 ms
248,712 KB
testcase_17 AC 270 ms
251,888 KB
testcase_18 AC 275 ms
251,964 KB
testcase_19 AC 264 ms
250,540 KB
testcase_20 AC 270 ms
249,932 KB
testcase_21 AC 116 ms
103,064 KB
testcase_22 AC 113 ms
99,988 KB
testcase_23 AC 115 ms
100,252 KB
testcase_24 AC 116 ms
103,164 KB
testcase_25 AC 114 ms
100,884 KB
testcase_26 AC 92 ms
83,692 KB
testcase_27 AC 94 ms
84,332 KB
testcase_28 AC 92 ms
83,472 KB
testcase_29 AC 92 ms
85,032 KB
testcase_30 AC 91 ms
82,348 KB
testcase_31 AC 89 ms
81,432 KB
testcase_32 AC 83 ms
77,320 KB
testcase_33 AC 86 ms
80,344 KB
testcase_34 AC 84 ms
77,860 KB
testcase_35 AC 89 ms
80,224 KB
testcase_36 AC 89 ms
80,348 KB
testcase_37 AC 86 ms
79,424 KB
testcase_38 AC 86 ms
79,332 KB
testcase_39 AC 83 ms
77,784 KB
testcase_40 AC 82 ms
77,932 KB
testcase_41 AC 81 ms
76,680 KB
testcase_42 AC 80 ms
76,672 KB
testcase_43 AC 292 ms
260,220 KB
testcase_44 AC 286 ms
260,144 KB
testcase_45 AC 290 ms
260,496 KB
testcase_46 AC 289 ms
260,340 KB
testcase_47 AC 291 ms
260,396 KB
testcase_48 AC 72 ms
71,136 KB
testcase_49 AC 72 ms
71,348 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] * (4 * n + 10)
B = 2 * n + 5
dp[B] = 0
for c0, c1 in b:
    ndp = [INF] * (4 * 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