結果

問題 No.1606 Stuffed Animals Keeper
ユーザー 👑 rin204rin204
提出日時 2021-07-16 21:38:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 131 ms / 3,000 ms
コード長 543 bytes
コンパイル時間 271 ms
コンパイル使用メモリ 82,192 KB
実行使用メモリ 76,896 KB
最終ジャッジ日時 2024-07-06 08:37:15
合計ジャッジ時間 4,999 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
52,532 KB
testcase_01 AC 37 ms
53,308 KB
testcase_02 AC 37 ms
52,880 KB
testcase_03 AC 87 ms
76,064 KB
testcase_04 AC 91 ms
76,416 KB
testcase_05 AC 62 ms
70,232 KB
testcase_06 AC 65 ms
73,648 KB
testcase_07 AC 84 ms
76,344 KB
testcase_08 AC 80 ms
76,264 KB
testcase_09 AC 64 ms
74,072 KB
testcase_10 AC 59 ms
69,644 KB
testcase_11 AC 52 ms
64,896 KB
testcase_12 AC 65 ms
74,184 KB
testcase_13 AC 42 ms
60,696 KB
testcase_14 AC 43 ms
60,340 KB
testcase_15 AC 43 ms
60,796 KB
testcase_16 AC 99 ms
76,760 KB
testcase_17 AC 99 ms
76,308 KB
testcase_18 AC 97 ms
76,608 KB
testcase_19 AC 96 ms
76,340 KB
testcase_20 AC 97 ms
76,584 KB
testcase_21 AC 72 ms
75,860 KB
testcase_22 AC 66 ms
73,964 KB
testcase_23 AC 72 ms
76,076 KB
testcase_24 AC 72 ms
76,212 KB
testcase_25 AC 70 ms
75,872 KB
testcase_26 AC 61 ms
71,764 KB
testcase_27 AC 61 ms
71,560 KB
testcase_28 AC 59 ms
70,288 KB
testcase_29 AC 61 ms
70,928 KB
testcase_30 AC 59 ms
70,004 KB
testcase_31 AC 60 ms
69,348 KB
testcase_32 AC 51 ms
64,752 KB
testcase_33 AC 59 ms
69,012 KB
testcase_34 AC 53 ms
65,988 KB
testcase_35 AC 60 ms
68,732 KB
testcase_36 AC 60 ms
69,792 KB
testcase_37 AC 59 ms
69,192 KB
testcase_38 AC 59 ms
68,952 KB
testcase_39 AC 52 ms
65,180 KB
testcase_40 AC 51 ms
64,996 KB
testcase_41 AC 45 ms
60,728 KB
testcase_42 AC 45 ms
62,504 KB
testcase_43 AC 124 ms
76,576 KB
testcase_44 AC 124 ms
76,884 KB
testcase_45 AC 131 ms
76,792 KB
testcase_46 AC 124 ms
76,896 KB
testcase_47 AC 128 ms
76,736 KB
testcase_48 AC 38 ms
53,760 KB
testcase_49 AC 37 ms
54,104 KB
testcase_50 AC 38 ms
52,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
alst = list(map(int, input().split()))
one = 0
vw = []
tot = 0
cnt = 0
for a in alst:
    if a == 2:
        if tot != 0:
            vw.append((cnt, tot))
        cnt = tot = 0
    elif a == 0:
        tot += 1
    else:
        cnt += 1
        tot += 1
        one += 1
if tot != 0:
    vw.append((cnt, tot))
dp = [-10 ** 20 for _ in range(one + 1)]
dp[0] = 0
for v, w in vw:
    for j in range(one, w - 1, -1):
        dp[j] = max(dp[j], dp[j - w] + v)

if dp[one] < 0:
    print(-1)
else:
    print(one - dp[-1])
        
0