結果
問題 | No.1606 Stuffed Animals Keeper |
ユーザー |
![]() |
提出日時 | 2021-07-17 10:20:34 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 65 ms / 3,000 ms |
コード長 | 1,146 bytes |
コンパイル時間 | 135 ms |
コンパイル使用メモリ | 82,416 KB |
実行使用メモリ | 68,172 KB |
最終ジャッジ日時 | 2024-07-06 21:54:43 |
合計ジャッジ時間 | 3,981 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 48 |
ソースコード
import syssys.setrecursionlimit(200005)int1 = lambda x: int(x)-1p2D = lambda x: print(*x, sep="\n")def II(): return int(sys.stdin.readline())def LI(): return list(map(int, sys.stdin.readline().split()))def LI1(): return list(map(int1, sys.stdin.readline().split()))def LLI(rows_number): return [LI() for _ in range(rows_number)]def LLI1(rows_number): return [LI1() for _ in range(rows_number)]def SI(): return sys.stdin.readline().rstrip()# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]inf = 10**16md = 998244353# md = 10**9+7n = II()aa = LI()+[2]c0 = c1 = 0s = 0seg = []for i, a in enumerate(aa):if a == 0:c0 += 1s += 1elif a == 1:c1 += 1elif c0+c1:seg.append((c0, c1))c0 = c1 = 0# print(seg)def chmin(j, val):if val < dp[j]: dp[j] = valm = len(seg)dp = [inf]*(s+1)dp[0] = 0for i, (c0, c1) in enumerate(seg):for j in range(s-c0-c1+1)[::-1]:if dp[j] == inf: continuechmin(j+c0+c1, dp[j]+c1)# print(dp)ans = dp[-1]if ans == inf: ans = -1print(ans)