結果

問題 No.1606 Stuffed Animals Keeper
ユーザー tonyu0tonyu0
提出日時 2022-09-21 16:11:58
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 777 bytes
コンパイル時間 283 ms
コンパイル使用メモリ 87,264 KB
実行使用メモリ 198,728 KB
最終ジャッジ日時 2023-08-23 20:01:05
合計ジャッジ時間 9,373 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,040 KB
testcase_01 AC 70 ms
71,052 KB
testcase_02 AC 71 ms
71,256 KB
testcase_03 AC 193 ms
126,948 KB
testcase_04 AC 186 ms
125,724 KB
testcase_05 AC 103 ms
82,684 KB
testcase_06 AC 120 ms
87,860 KB
testcase_07 AC 158 ms
104,720 KB
testcase_08 AC 153 ms
104,944 KB
testcase_09 AC 115 ms
86,376 KB
testcase_10 AC 103 ms
81,844 KB
testcase_11 AC 91 ms
76,652 KB
testcase_12 AC 122 ms
88,292 KB
testcase_13 AC 79 ms
76,496 KB
testcase_14 AC 78 ms
76,380 KB
testcase_15 AC 76 ms
76,304 KB
testcase_16 AC 221 ms
148,272 KB
testcase_17 AC 220 ms
148,652 KB
testcase_18 AC 223 ms
147,744 KB
testcase_19 AC 223 ms
148,088 KB
testcase_20 AC 222 ms
147,480 KB
testcase_21 AC 126 ms
88,868 KB
testcase_22 AC 123 ms
88,856 KB
testcase_23 AC 124 ms
87,884 KB
testcase_24 AC 125 ms
88,948 KB
testcase_25 AC 123 ms
88,404 KB
testcase_26 AC 99 ms
81,048 KB
testcase_27 AC 102 ms
81,304 KB
testcase_28 AC 99 ms
80,668 KB
testcase_29 AC 102 ms
81,392 KB
testcase_30 AC 94 ms
76,936 KB
testcase_31 AC 91 ms
76,700 KB
testcase_32 AC 91 ms
76,432 KB
testcase_33 AC 92 ms
76,564 KB
testcase_34 AC 84 ms
76,884 KB
testcase_35 AC 91 ms
76,696 KB
testcase_36 AC 90 ms
76,544 KB
testcase_37 AC 90 ms
76,660 KB
testcase_38 WA -
testcase_39 AC 84 ms
76,716 KB
testcase_40 AC 83 ms
76,728 KB
testcase_41 AC 80 ms
76,480 KB
testcase_42 AC 80 ms
76,624 KB
testcase_43 AC 268 ms
198,388 KB
testcase_44 AC 266 ms
198,252 KB
testcase_45 AC 267 ms
198,728 KB
testcase_46 AC 265 ms
198,140 KB
testcase_47 AC 266 ms
198,420 KB
testcase_48 AC 70 ms
71,088 KB
testcase_49 AC 69 ms
71,472 KB
testcase_50 AC 70 ms
71,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n=int(input())
a=list(map(int, input().split()))
b=[]
L=0
O=0
alllen=0
allone=0
for i in range(n):
    if a[i] == 2:
        if L>0:
            if 0<O<L:
                b.append([L, O])
            L=0
            O=0
    else:
        alllen+=1
        L+=1
        if a[i]==1:
            allone+=1
            O+=1
if L>0:
    b.append([L, O])

m=len(b)
o=n*2+10
dp=[[1e9]*(o) for _ in range(m+1)]
dp[0][n]=0
for i in range(m):
    len, one = b[i]
    zero = len - one
    for j in range(o):
        if dp[i][j]==1e9:
            continue
        if j + one < o:
            dp[i+1][j+one] = min(dp[i+1][j+one], dp[i][j] + one)
        if j - zero >= 0:
            dp[i+1][j-zero]=min(dp[i+1][j-zero],dp[i][j])

if dp[m][n] == 1e9:
    print(-1)
else:
    print(dp[m][n])
0