結果

問題 No.1606 Stuffed Animals Keeper
ユーザー tonyu0tonyu0
提出日時 2022-09-21 16:15:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 471 ms / 3,000 ms
コード長 744 bytes
コンパイル時間 283 ms
コンパイル使用メモリ 86,920 KB
実行使用メモリ 313,008 KB
最終ジャッジ日時 2023-08-23 20:01:28
合計ジャッジ時間 11,176 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,296 KB
testcase_01 AC 74 ms
71,292 KB
testcase_02 AC 74 ms
71,216 KB
testcase_03 AC 277 ms
171,792 KB
testcase_04 AC 303 ms
194,160 KB
testcase_05 AC 127 ms
88,840 KB
testcase_06 AC 160 ms
106,232 KB
testcase_07 AC 237 ms
148,940 KB
testcase_08 AC 224 ms
149,136 KB
testcase_09 AC 149 ms
104,812 KB
testcase_10 AC 121 ms
86,728 KB
testcase_11 AC 106 ms
81,272 KB
testcase_12 AC 160 ms
105,672 KB
testcase_13 AC 80 ms
76,324 KB
testcase_14 AC 79 ms
76,216 KB
testcase_15 AC 78 ms
76,200 KB
testcase_16 AC 367 ms
240,040 KB
testcase_17 AC 368 ms
239,928 KB
testcase_18 AC 373 ms
239,796 KB
testcase_19 AC 364 ms
239,800 KB
testcase_20 AC 375 ms
240,252 KB
testcase_21 AC 130 ms
88,944 KB
testcase_22 AC 129 ms
88,924 KB
testcase_23 AC 128 ms
87,912 KB
testcase_24 AC 130 ms
88,848 KB
testcase_25 AC 127 ms
88,924 KB
testcase_26 AC 103 ms
80,888 KB
testcase_27 AC 99 ms
81,084 KB
testcase_28 AC 100 ms
80,464 KB
testcase_29 AC 103 ms
81,220 KB
testcase_30 AC 95 ms
76,524 KB
testcase_31 AC 95 ms
76,564 KB
testcase_32 AC 85 ms
76,412 KB
testcase_33 AC 91 ms
76,688 KB
testcase_34 AC 85 ms
76,524 KB
testcase_35 AC 92 ms
76,720 KB
testcase_36 AC 93 ms
76,376 KB
testcase_37 AC 91 ms
76,716 KB
testcase_38 AC 92 ms
76,656 KB
testcase_39 AC 85 ms
76,552 KB
testcase_40 AC 84 ms
76,420 KB
testcase_41 AC 80 ms
76,196 KB
testcase_42 AC 82 ms
76,360 KB
testcase_43 AC 467 ms
312,344 KB
testcase_44 AC 464 ms
312,880 KB
testcase_45 AC 471 ms
312,840 KB
testcase_46 AC 465 ms
313,008 KB
testcase_47 AC 466 ms
312,852 KB
testcase_48 AC 74 ms
71,280 KB
testcase_49 AC 73 ms
71,312 KB
testcase_50 AC 75 ms
71,428 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:
            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