結果

問題 No.1606 Stuffed Animals Keeper
ユーザー rlangevinrlangevin
提出日時 2023-04-04 08:58:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 580 ms / 3,000 ms
コード長 675 bytes
コンパイル時間 1,784 ms
コンパイル使用メモリ 81,540 KB
実行使用メモリ 79,784 KB
最終ジャッジ日時 2023-10-26 02:39:17
合計ジャッジ時間 10,683 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
61,780 KB
testcase_01 AC 42 ms
61,780 KB
testcase_02 AC 42 ms
61,780 KB
testcase_03 AC 240 ms
77,028 KB
testcase_04 AC 255 ms
77,056 KB
testcase_05 AC 137 ms
76,192 KB
testcase_06 AC 166 ms
76,496 KB
testcase_07 AC 211 ms
76,768 KB
testcase_08 AC 212 ms
76,828 KB
testcase_09 AC 150 ms
76,508 KB
testcase_10 AC 133 ms
76,248 KB
testcase_11 AC 102 ms
75,852 KB
testcase_12 AC 158 ms
76,468 KB
testcase_13 AC 45 ms
64,304 KB
testcase_14 AC 43 ms
62,244 KB
testcase_15 AC 580 ms
79,784 KB
testcase_16 AC 285 ms
77,276 KB
testcase_17 AC 288 ms
77,272 KB
testcase_18 AC 288 ms
77,276 KB
testcase_19 AC 285 ms
77,272 KB
testcase_20 AC 287 ms
77,280 KB
testcase_21 AC 88 ms
75,892 KB
testcase_22 AC 86 ms
75,960 KB
testcase_23 AC 87 ms
76,260 KB
testcase_24 AC 88 ms
75,952 KB
testcase_25 AC 85 ms
75,956 KB
testcase_26 AC 64 ms
72,604 KB
testcase_27 AC 64 ms
72,604 KB
testcase_28 AC 65 ms
72,612 KB
testcase_29 AC 66 ms
72,604 KB
testcase_30 AC 69 ms
72,604 KB
testcase_31 AC 62 ms
70,536 KB
testcase_32 AC 54 ms
68,476 KB
testcase_33 AC 57 ms
70,536 KB
testcase_34 AC 54 ms
68,480 KB
testcase_35 AC 60 ms
70,556 KB
testcase_36 AC 59 ms
70,552 KB
testcase_37 AC 59 ms
70,556 KB
testcase_38 AC 57 ms
70,536 KB
testcase_39 AC 55 ms
68,480 KB
testcase_40 AC 53 ms
68,480 KB
testcase_41 AC 55 ms
68,496 KB
testcase_42 AC 55 ms
68,496 KB
testcase_43 AC 269 ms
77,240 KB
testcase_44 AC 263 ms
77,216 KB
testcase_45 AC 266 ms
77,232 KB
testcase_46 AC 262 ms
77,216 KB
testcase_47 AC 265 ms
77,164 KB
testcase_48 AC 40 ms
59,592 KB
testcase_49 AC 43 ms
61,812 KB
testcase_50 AC 43 ms
61,812 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
A = list(map(int, input().split()))
X, Y = [], []
cntX, cntY = 0, 0
for a in A:
    if a == 2:
        X.append(cntX)
        Y.append(cntY)
        cntX, cntY = 0, 0
    elif a == 0:
        cntX += 1
    else:
        cntY += 1
X.append(cntX)
Y.append(cntY)
M = len(X)
geta = 5005
inf = 10 ** 18
pre = [inf] * (2 * geta)
pre[geta] = 0
for i in range(M):
    dp = [inf] * (2 * geta)
    for j in range(2 * geta):
        if j + X[i] < 2 * geta:
            dp[j + X[i]] = min(dp[j + X[i]], pre[j] + X[i])
        if j - Y[i] >= 0:
            dp[j - Y[i]] = min(dp[j - Y[i]], pre[j])
    dp, pre = pre, dp

print(pre[geta]) if pre[geta] < inf else print(-1)
0