結果

問題 No.27 板の準備
ユーザー wotsushiwotsushi
提出日時 2017-04-01 21:51:33
言語 Ruby
(3.3.0)
結果
AC  
実行時間 460 ms / 5,000 ms
コード長 498 bytes
コンパイル時間 41 ms
コンパイル使用メモリ 11,568 KB
実行使用メモリ 40,276 KB
最終ジャッジ日時 2023-08-27 04:39:17
合計ジャッジ時間 6,849 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
17,384 KB
testcase_01 AC 162 ms
20,980 KB
testcase_02 AC 314 ms
28,696 KB
testcase_03 AC 149 ms
20,448 KB
testcase_04 AC 345 ms
37,024 KB
testcase_05 AC 298 ms
30,780 KB
testcase_06 AC 395 ms
37,036 KB
testcase_07 AC 397 ms
37,256 KB
testcase_08 AC 460 ms
40,276 KB
testcase_09 AC 427 ms
37,296 KB
testcase_10 AC 360 ms
36,820 KB
testcase_11 AC 333 ms
31,836 KB
testcase_12 AC 361 ms
37,324 KB
testcase_13 AC 324 ms
30,672 KB
testcase_14 AC 269 ms
28,200 KB
testcase_15 AC 345 ms
36,932 KB
testcase_16 AC 218 ms
25,724 KB
testcase_17 AC 348 ms
31,884 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

V0, V1, V2, V3 = gets.split.map(&:to_i)
D = [*1..30]
def f(v, a, b, c)
  @dp ||= {}
  @dp[[v, a, b, c]] ||= if v < 0
                          Float::INFINITY
                        elsif v == 0
                          0
                        else
                          [f(v - a, a, b, c), f(v - b, a, b, c), f(v - c, a, b, c)].min + 1
                        end
end
ans = D.combination(3).map {|a, b, c|
  f(V0, a, b, c) + f(V1, a, b, c) + f(V2, a, b, c) + f(V3, a, b, c)
}.min
puts ans
0