結果

問題 No.1606 Stuffed Animals Keeper
ユーザー horitaka1999horitaka1999
提出日時 2021-12-10 23:49:30
言語 PyPy3
(7.3.13)
結果
MLE  
実行時間 -
コード長 853 bytes
コンパイル時間 1,574 ms
コンパイル使用メモリ 86,580 KB
実行使用メモリ 693,192 KB
最終ジャッジ日時 2023-09-25 22:58:33
合計ジャッジ時間 17,633 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
75,804 KB
testcase_01 AC 72 ms
75,704 KB
testcase_02 AC 74 ms
75,716 KB
testcase_03 AC 445 ms
258,224 KB
testcase_04 AC 486 ms
304,244 KB
testcase_05 AC 247 ms
169,408 KB
testcase_06 AC 296 ms
190,024 KB
testcase_07 AC 403 ms
236,032 KB
testcase_08 AC 405 ms
258,368 KB
testcase_09 AC 288 ms
190,900 KB
testcase_10 AC 216 ms
146,884 KB
testcase_11 AC 177 ms
125,756 KB
testcase_12 AC 284 ms
190,276 KB
testcase_13 AC 78 ms
76,356 KB
testcase_14 AC 79 ms
76,600 KB
testcase_15 MLE -
testcase_16 AC 848 ms
326,688 KB
testcase_17 AC 554 ms
327,488 KB
testcase_18 AC 542 ms
326,432 KB
testcase_19 AC 554 ms
326,896 KB
testcase_20 AC 546 ms
326,556 KB
testcase_21 AC 153 ms
102,152 KB
testcase_22 AC 135 ms
88,908 KB
testcase_23 AC 138 ms
87,804 KB
testcase_24 AC 147 ms
102,132 KB
testcase_25 AC 130 ms
88,740 KB
testcase_26 AC 104 ms
80,932 KB
testcase_27 AC 108 ms
81,072 KB
testcase_28 AC 106 ms
80,956 KB
testcase_29 AC 106 ms
81,588 KB
testcase_30 AC 104 ms
80,240 KB
testcase_31 AC 98 ms
76,740 KB
testcase_32 AC 81 ms
76,384 KB
testcase_33 AC 94 ms
76,584 KB
testcase_34 AC 86 ms
76,580 KB
testcase_35 AC 98 ms
76,604 KB
testcase_36 AC 96 ms
76,492 KB
testcase_37 AC 96 ms
76,688 KB
testcase_38 AC 91 ms
76,616 KB
testcase_39 AC 86 ms
76,612 KB
testcase_40 AC 88 ms
76,660 KB
testcase_41 AC 83 ms
76,400 KB
testcase_42 AC 80 ms
76,356 KB
testcase_43 AC 483 ms
312,352 KB
testcase_44 AC 479 ms
312,352 KB
testcase_45 AC 506 ms
312,364 KB
testcase_46 AC 478 ms
312,380 KB
testcase_47 AC 488 ms
312,292 KB
testcase_48 AC 80 ms
75,672 KB
testcase_49 AC 80 ms
75,860 KB
testcase_50 AC 80 ms
75,944 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
        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