結果
| 問題 |
No.1606 Stuffed Animals Keeper
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-07-16 22:22:21 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 462 ms / 3,000 ms |
| コード長 | 571 bytes |
| コンパイル時間 | 196 ms |
| コンパイル使用メモリ | 12,416 KB |
| 実行使用メモリ | 44,464 KB |
| 最終ジャッジ日時 | 2024-07-06 09:47:25 |
| 合計ジャッジ時間 | 24,380 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 48 |
ソースコード
import numpy as np
N = int(input())
A = tuple(map(int, input().split()))
INF = 10000
c, h = 0, 0 # 肉食, 草食
dp = np.full(N + 1, INF)
dp[0] = 0
for i in range(N + 1):
if i == N or A[i] == 2:
if c == h == 0:
continue
new_dp = dp + c # 草食に揃える
new_dp[c + h:] = np.minimum(new_dp[c + h:], dp[:-c - h] + h) # 肉食に揃える
dp = new_dp
c, h = 0, 0
elif A[i] == 0:
c += 1
elif A[i] == 1:
h += 1
res = dp[A.count(0)]
if res >= INF:
print(-1)
else:
print(res // 2)