結果

問題 No.1606 Stuffed Animals Keeper
ユーザー hir355hir355
提出日時 2021-07-16 22:27:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 189 ms / 3,000 ms
コード長 628 bytes
コンパイル時間 285 ms
コンパイル使用メモリ 86,924 KB
実行使用メモリ 88,196 KB
最終ジャッジ日時 2023-09-20 14:43:37
合計ジャッジ時間 8,214 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,248 KB
testcase_01 AC 70 ms
70,980 KB
testcase_02 AC 74 ms
71,028 KB
testcase_03 AC 155 ms
87,876 KB
testcase_04 AC 164 ms
87,432 KB
testcase_05 AC 101 ms
76,564 KB
testcase_06 AC 121 ms
82,740 KB
testcase_07 AC 146 ms
87,512 KB
testcase_08 AC 146 ms
87,668 KB
testcase_09 AC 108 ms
76,636 KB
testcase_10 AC 103 ms
76,588 KB
testcase_11 AC 94 ms
76,636 KB
testcase_12 AC 117 ms
82,588 KB
testcase_13 AC 76 ms
76,508 KB
testcase_14 AC 81 ms
76,328 KB
testcase_15 AC 84 ms
76,412 KB
testcase_16 AC 187 ms
87,188 KB
testcase_17 AC 185 ms
87,640 KB
testcase_18 AC 184 ms
87,344 KB
testcase_19 AC 185 ms
87,180 KB
testcase_20 AC 189 ms
87,324 KB
testcase_21 AC 110 ms
76,884 KB
testcase_22 AC 108 ms
77,092 KB
testcase_23 AC 107 ms
77,348 KB
testcase_24 AC 106 ms
77,092 KB
testcase_25 AC 104 ms
76,320 KB
testcase_26 AC 94 ms
76,392 KB
testcase_27 AC 93 ms
76,260 KB
testcase_28 AC 97 ms
76,648 KB
testcase_29 AC 96 ms
76,260 KB
testcase_30 AC 95 ms
76,436 KB
testcase_31 AC 91 ms
76,424 KB
testcase_32 AC 84 ms
76,360 KB
testcase_33 AC 91 ms
76,388 KB
testcase_34 AC 86 ms
76,304 KB
testcase_35 AC 96 ms
76,440 KB
testcase_36 AC 93 ms
76,608 KB
testcase_37 AC 91 ms
76,248 KB
testcase_38 AC 93 ms
76,412 KB
testcase_39 AC 85 ms
76,488 KB
testcase_40 AC 84 ms
76,228 KB
testcase_41 AC 86 ms
76,380 KB
testcase_42 AC 85 ms
76,404 KB
testcase_43 AC 165 ms
88,196 KB
testcase_44 AC 167 ms
87,816 KB
testcase_45 AC 169 ms
88,024 KB
testcase_46 AC 166 ms
87,912 KB
testcase_47 AC 164 ms
87,756 KB
testcase_48 AC 73 ms
71,364 KB
testcase_49 AC 73 ms
71,324 KB
testcase_50 AC 72 ms
71,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
a = list(map(int, input().split()))
p = [0]
q = [0]
for i in range(n):
    if a[i] == 2:
        p.append(0)
        q.append(0)
    elif a[i] == 1:
        p[-1] += 1
        q[-1] += 1
    else:
        q[-1] += 1
m = len(p)
k = sum(p)
dp = [[n * 2] * (k + 1) for _ in range(m + 1)]
dp[0][0] = 0
for i in range(m):
    for j in range(k + 1):
        if j + q[i] <= k:
            if dp[i + 1][j + q[i]] > dp[i][j]:
                dp[i + 1][j + q[i]] = dp[i][j]
        if dp[i + 1][j] > dp[i][j] + p[i]:
            dp[i + 1][j] = dp[i][j] + p[i]
if dp[m][k] == n * 2:
    print(-1)
else:
    print(dp[m][k])
0