結果

問題 No.1606 Stuffed Animals Keeper
ユーザー horitaka1999horitaka1999
提出日時 2021-12-10 23:51:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 470 ms / 3,000 ms
コード長 898 bytes
コンパイル時間 415 ms
コンパイル使用メモリ 86,888 KB
実行使用メモリ 311,176 KB
最終ジャッジ日時 2023-09-25 22:59:53
合計ジャッジ時間 12,334 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
75,820 KB
testcase_01 AC 75 ms
75,912 KB
testcase_02 AC 78 ms
75,672 KB
testcase_03 AC 296 ms
191,568 KB
testcase_04 AC 331 ms
213,816 KB
testcase_05 AC 181 ms
126,336 KB
testcase_06 AC 217 ms
146,940 KB
testcase_07 AC 288 ms
191,284 KB
testcase_08 AC 283 ms
191,632 KB
testcase_09 AC 208 ms
146,972 KB
testcase_10 AC 173 ms
125,832 KB
testcase_11 AC 143 ms
105,492 KB
testcase_12 AC 223 ms
147,244 KB
testcase_13 AC 79 ms
76,392 KB
testcase_14 AC 78 ms
76,392 KB
testcase_15 AC 78 ms
76,148 KB
testcase_16 AC 399 ms
236,464 KB
testcase_17 AC 375 ms
236,436 KB
testcase_18 AC 375 ms
236,676 KB
testcase_19 AC 376 ms
236,796 KB
testcase_20 AC 368 ms
236,724 KB
testcase_21 AC 145 ms
102,180 KB
testcase_22 AC 129 ms
88,992 KB
testcase_23 AC 134 ms
87,900 KB
testcase_24 AC 147 ms
102,156 KB
testcase_25 AC 134 ms
88,672 KB
testcase_26 AC 101 ms
80,876 KB
testcase_27 AC 102 ms
81,460 KB
testcase_28 AC 101 ms
80,860 KB
testcase_29 AC 102 ms
81,400 KB
testcase_30 AC 107 ms
80,064 KB
testcase_31 AC 98 ms
76,380 KB
testcase_32 AC 80 ms
76,484 KB
testcase_33 AC 94 ms
76,624 KB
testcase_34 AC 82 ms
76,700 KB
testcase_35 AC 93 ms
76,392 KB
testcase_36 AC 91 ms
76,456 KB
testcase_37 AC 92 ms
76,400 KB
testcase_38 AC 88 ms
76,472 KB
testcase_39 AC 79 ms
76,464 KB
testcase_40 AC 81 ms
76,492 KB
testcase_41 AC 81 ms
76,324 KB
testcase_42 AC 79 ms
76,196 KB
testcase_43 AC 470 ms
310,928 KB
testcase_44 AC 459 ms
310,784 KB
testcase_45 AC 461 ms
310,836 KB
testcase_46 AC 450 ms
310,984 KB
testcase_47 AC 463 ms
311,176 KB
testcase_48 AC 74 ms
75,820 KB
testcase_49 AC 73 ms
75,668 KB
testcase_50 AC 71 ms
71,100 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
A = list(map(int,input().split()))
B = [(0,0)]
x = 0
y = 0
for i in range(N):
    if A[i] == 2 or i == N-1:
        if A[i] == 0:
            x += 1
        elif A[i] == 1:
            y += 1
        if x == y == 0:
            continue
        B.append((x,y))
        x = 0
        y = 0
    elif A[i] == 0:
        x += 1
    elif A[i] == 1:
        y += 1
INF = float('inf')
dp = [[INF] * 10001 for _ in range(len(B))]
def check(t):
    if 0 <= t < 10001:
        return True
    else:
        return False
dp[0][5000] = 0
for i in range(1,len(B)):
    x,y = B[i]
    for s in range(10001):
        if dp[i-1][s] == INF:
            continue
        if check(s-x):
            dp[i][s-x] = min(dp[i-1][s] + x,dp[i][s-x])
        if check(s+y):
            dp[i][s+y] = min(dp[i-1][s] + y,dp[i][s+y])
ans = dp[len(B)-1][5000]
if ans == INF:
    print(-1)
else:
    print(ans//2)
0