結果

問題 No.1606 Stuffed Animals Keeper
ユーザー tassei903tassei903
提出日時 2021-07-16 22:32:02
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 200 ms / 3,000 ms
コード長 917 bytes
コンパイル時間 783 ms
コンパイル使用メモリ 87,228 KB
実行使用メモリ 99,836 KB
最終ジャッジ日時 2023-09-20 14:50:26
合計ジャッジ時間 8,398 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,364 KB
testcase_01 AC 72 ms
71,260 KB
testcase_02 AC 71 ms
71,120 KB
testcase_03 AC 140 ms
86,188 KB
testcase_04 AC 151 ms
85,680 KB
testcase_05 AC 99 ms
76,740 KB
testcase_06 AC 111 ms
80,824 KB
testcase_07 AC 135 ms
84,976 KB
testcase_08 AC 130 ms
84,296 KB
testcase_09 AC 105 ms
76,344 KB
testcase_10 AC 102 ms
77,432 KB
testcase_11 AC 93 ms
76,436 KB
testcase_12 AC 113 ms
81,172 KB
testcase_13 AC 75 ms
76,252 KB
testcase_14 AC 79 ms
76,512 KB
testcase_15 AC 74 ms
76,116 KB
testcase_16 AC 164 ms
85,480 KB
testcase_17 AC 163 ms
84,812 KB
testcase_18 AC 163 ms
85,220 KB
testcase_19 AC 169 ms
85,136 KB
testcase_20 AC 167 ms
84,604 KB
testcase_21 AC 106 ms
76,376 KB
testcase_22 AC 109 ms
76,692 KB
testcase_23 AC 113 ms
80,448 KB
testcase_24 AC 114 ms
80,348 KB
testcase_25 AC 104 ms
76,368 KB
testcase_26 AC 99 ms
76,988 KB
testcase_27 AC 101 ms
76,832 KB
testcase_28 AC 98 ms
76,988 KB
testcase_29 AC 99 ms
76,520 KB
testcase_30 AC 99 ms
77,228 KB
testcase_31 AC 94 ms
76,204 KB
testcase_32 AC 86 ms
76,304 KB
testcase_33 AC 95 ms
76,652 KB
testcase_34 AC 86 ms
76,448 KB
testcase_35 AC 96 ms
76,520 KB
testcase_36 AC 95 ms
76,420 KB
testcase_37 AC 95 ms
76,456 KB
testcase_38 AC 93 ms
76,404 KB
testcase_39 AC 87 ms
76,388 KB
testcase_40 AC 85 ms
76,260 KB
testcase_41 AC 83 ms
76,404 KB
testcase_42 AC 83 ms
76,312 KB
testcase_43 AC 192 ms
99,120 KB
testcase_44 AC 198 ms
99,836 KB
testcase_45 AC 200 ms
99,420 KB
testcase_46 AC 200 ms
99,736 KB
testcase_47 AC 197 ms
99,000 KB
testcase_48 AC 78 ms
70,908 KB
testcase_49 AC 76 ms
71,248 KB
testcase_50 AC 76 ms
71,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda :sys.stdin.readline()[:-1]
ni = lambda :int(input())
na = lambda :list(map(int,input().split()))
sys.setrecursionlimit(10**7)
yes = lambda :print("yes");Yes = lambda :print("Yes")
no = lambda :print("no");No = lambda :print("No")
#################################################
n = ni()
a = na()+[2]
A = []
B = []
x,y = 0,0
for i in range(n+1):
    if a[i]==2:
        if x==0 and y==0:continue
        A.append(x)
        B.append(y)
        x = 0
        y = 0
    elif a[i]==0:
        x+=1
    else:
        y+=1
S = sum(B)
N = len(A)
AB = [A[i]+B[i] for i in range(N)]
inf = 10**15
dp = [[inf for j in range(S+1)]for i in range(N+1)]
dp[0][0] = 0
for i in range(N):
    for j in range(S+1):
        if j-AB[i]>=0:
            dp[i+1][j] = min(dp[i+1][j],dp[i][j-AB[i]]+A[i])
        dp[i+1][j] = min(dp[i+1][j],dp[i][j])

if dp[-1][-1]==inf:
    print(-1)
else:
    print(dp[-1][-1])
0