結果

問題 No.1606 Stuffed Animals Keeper
ユーザー googol_S0googol_S0
提出日時 2021-07-16 21:28:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,866 ms / 3,000 ms
コード長 476 bytes
コンパイル時間 357 ms
コンパイル使用メモリ 87,172 KB
実行使用メモリ 469,240 KB
最終ジャッジ日時 2023-09-20 13:02:31
合計ジャッジ時間 19,093 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,252 KB
testcase_01 AC 73 ms
71,296 KB
testcase_02 AC 73 ms
71,372 KB
testcase_03 AC 503 ms
157,772 KB
testcase_04 AC 602 ms
179,280 KB
testcase_05 AC 197 ms
91,088 KB
testcase_06 AC 279 ms
111,084 KB
testcase_07 AC 449 ms
143,588 KB
testcase_08 AC 422 ms
141,376 KB
testcase_09 AC 245 ms
103,532 KB
testcase_10 AC 193 ms
90,876 KB
testcase_11 AC 139 ms
83,548 KB
testcase_12 AC 271 ms
109,556 KB
testcase_13 AC 84 ms
76,596 KB
testcase_14 AC 85 ms
76,680 KB
testcase_15 AC 1,866 ms
469,240 KB
testcase_16 AC 825 ms
209,824 KB
testcase_17 AC 772 ms
211,600 KB
testcase_18 AC 774 ms
210,196 KB
testcase_19 AC 753 ms
209,648 KB
testcase_20 AC 765 ms
210,208 KB
testcase_21 AC 193 ms
90,524 KB
testcase_22 AC 185 ms
90,036 KB
testcase_23 AC 185 ms
90,024 KB
testcase_24 AC 188 ms
90,588 KB
testcase_25 AC 186 ms
90,372 KB
testcase_26 AC 142 ms
81,772 KB
testcase_27 AC 144 ms
81,948 KB
testcase_28 AC 144 ms
81,880 KB
testcase_29 AC 150 ms
82,408 KB
testcase_30 AC 142 ms
81,368 KB
testcase_31 AC 140 ms
80,784 KB
testcase_32 AC 104 ms
77,392 KB
testcase_33 AC 136 ms
79,832 KB
testcase_34 AC 104 ms
77,316 KB
testcase_35 AC 132 ms
79,440 KB
testcase_36 AC 137 ms
80,168 KB
testcase_37 AC 132 ms
79,296 KB
testcase_38 AC 130 ms
78,864 KB
testcase_39 AC 104 ms
77,332 KB
testcase_40 AC 103 ms
77,124 KB
testcase_41 AC 101 ms
77,432 KB
testcase_42 AC 100 ms
77,216 KB
testcase_43 AC 748 ms
208,680 KB
testcase_44 AC 752 ms
209,008 KB
testcase_45 AC 751 ms
208,528 KB
testcase_46 AC 749 ms
208,520 KB
testcase_47 AC 745 ms
208,600 KB
testcase_48 AC 74 ms
71,328 KB
testcase_49 AC 72 ms
71,456 KB
testcase_50 AC 73 ms
71,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())
A=list(map(int,input().split()))
C=[[0,0]]
for i in range(N):
  if A[i]==2:
    C.append([0,0])
  else:
    C[-1][A[i]]+=1
M=len(C)
INF=10**9
DP=[[INF]*(N*2+1) for i in range(M+1)]
DP[0][0]=0
for i in range(M):
  for j in range(-N,N+1):
    x=j+C[i][0]
    if abs(x)<=N:
      DP[i+1][x]=min(DP[i+1][x],DP[i][j]+C[i][0])
    x=j-C[i][1]
    if abs(x)<=N:
      DP[i+1][x]=min(DP[i+1][x],DP[i][j]+C[i][1])
if DP[M][0]<INF:
  print(DP[M][0]>>1)
else:
  print(-1)
0