結果

問題 No.27 板の準備
ユーザー wotsushiwotsushi
提出日時 2017-04-01 21:47:30
言語 Ruby
(3.3.0)
結果
AC  
実行時間 3,082 ms / 5,000 ms
コード長 497 bytes
コンパイル時間 231 ms
コンパイル使用メモリ 11,180 KB
実行使用メモリ 203,108 KB
最終ジャッジ日時 2023-09-22 02:22:32
合計ジャッジ時間 33,715 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 357 ms
31,524 KB
testcase_01 AC 688 ms
60,484 KB
testcase_02 AC 1,674 ms
109,768 KB
testcase_03 AC 669 ms
60,236 KB
testcase_04 AC 1,945 ms
134,176 KB
testcase_05 AC 1,707 ms
126,132 KB
testcase_06 AC 2,253 ms
148,248 KB
testcase_07 AC 2,234 ms
142,956 KB
testcase_08 AC 3,082 ms
203,108 KB
testcase_09 AC 2,374 ms
152,468 KB
testcase_10 AC 2,014 ms
134,104 KB
testcase_11 AC 1,849 ms
132,428 KB
testcase_12 AC 2,033 ms
135,940 KB
testcase_13 AC 1,747 ms
126,412 KB
testcase_14 AC 1,524 ms
107,780 KB
testcase_15 AC 2,051 ms
134,840 KB
testcase_16 AC 1,222 ms
103,752 KB
testcase_17 AC 1,985 ms
133,020 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.product(D, D).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