結果

問題 No.1606 Stuffed Animals Keeper
ユーザー yuruhiyayuruhiya
提出日時 2021-07-17 13:15:28
言語 Crystal
(1.11.2)
結果
AC  
実行時間 616 ms / 3,000 ms
コード長 370 bytes
コンパイル時間 20,274 ms
コンパイル使用メモリ 254,732 KB
実行使用メモリ 5,428 KB
最終ジャッジ日時 2023-09-21 06:38:19
合計ジャッジ時間 24,220 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,460 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 3 ms
4,444 KB
testcase_03 AC 127 ms
4,996 KB
testcase_04 AC 160 ms
5,016 KB
testcase_05 AC 31 ms
5,136 KB
testcase_06 AC 55 ms
5,100 KB
testcase_07 AC 107 ms
5,020 KB
testcase_08 AC 102 ms
4,912 KB
testcase_09 AC 43 ms
5,108 KB
testcase_10 AC 27 ms
5,144 KB
testcase_11 AC 14 ms
5,084 KB
testcase_12 AC 53 ms
5,092 KB
testcase_13 AC 3 ms
4,524 KB
testcase_14 AC 3 ms
4,564 KB
testcase_15 AC 616 ms
5,080 KB
testcase_16 AC 208 ms
5,372 KB
testcase_17 AC 210 ms
5,268 KB
testcase_18 AC 209 ms
5,248 KB
testcase_19 AC 208 ms
5,228 KB
testcase_20 AC 209 ms
5,428 KB
testcase_21 AC 24 ms
4,980 KB
testcase_22 AC 22 ms
5,092 KB
testcase_23 AC 22 ms
4,972 KB
testcase_24 AC 24 ms
4,948 KB
testcase_25 AC 22 ms
5,088 KB
testcase_26 AC 9 ms
5,048 KB
testcase_27 AC 10 ms
5,120 KB
testcase_28 AC 9 ms
5,144 KB
testcase_29 AC 10 ms
5,108 KB
testcase_30 AC 8 ms
5,128 KB
testcase_31 AC 7 ms
5,112 KB
testcase_32 AC 4 ms
4,824 KB
testcase_33 AC 6 ms
5,100 KB
testcase_34 AC 4 ms
4,816 KB
testcase_35 AC 6 ms
5,176 KB
testcase_36 AC 6 ms
5,000 KB
testcase_37 AC 6 ms
5,052 KB
testcase_38 AC 5 ms
4,996 KB
testcase_39 AC 4 ms
4,804 KB
testcase_40 AC 4 ms
4,700 KB
testcase_41 AC 3 ms
4,532 KB
testcase_42 AC 3 ms
4,704 KB
testcase_43 AC 205 ms
5,368 KB
testcase_44 AC 207 ms
5,376 KB
testcase_45 AC 207 ms
5,236 KB
testcase_46 AC 207 ms
5,348 KB
testcase_47 AC 207 ms
5,276 KB
testcase_48 AC 2 ms
4,396 KB
testcase_49 AC 2 ms
4,432 KB
testcase_50 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = read_line.to_i
ans = read_line.delete(' ').split('2').map { |s|
  {s.count('0'), s.count('1')}
}.reduce([0] + [10**9] * (2*n)) { |dp, (a, b)|
  (-n..n).each_with_object([10**9] * (2*n + 1)) do |i, dp2|
    dp2[i - a] = {dp2[i - a], dp[i] + a}.min if i - a >= -n
    dp2[i + b] = {dp2[i + b], dp[i] + b}.min if i + b <= +n
  end
}[0]
puts ans < 10**9 ? ans // 2 : -1
0