結果

問題 No.27 板の準備
ユーザー maimai
提出日時 2017-06-29 13:42:12
言語 Ruby
(3.3.0)
結果
AC  
実行時間 296 ms / 5,000 ms
コード長 783 bytes
コンパイル時間 135 ms
コンパイル使用メモリ 11,176 KB
実行使用メモリ 16,028 KB
最終ジャッジ日時 2023-08-27 04:42:13
合計ジャッジ時間 4,751 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 115 ms
15,380 KB
testcase_01 AC 121 ms
15,396 KB
testcase_02 AC 214 ms
15,800 KB
testcase_03 AC 125 ms
15,312 KB
testcase_04 AC 214 ms
15,828 KB
testcase_05 AC 188 ms
16,028 KB
testcase_06 AC 242 ms
15,804 KB
testcase_07 AC 250 ms
15,716 KB
testcase_08 AC 296 ms
15,700 KB
testcase_09 AC 258 ms
15,540 KB
testcase_10 AC 221 ms
15,648 KB
testcase_11 AC 207 ms
15,816 KB
testcase_12 AC 214 ms
15,788 KB
testcase_13 AC 202 ms
15,616 KB
testcase_14 AC 172 ms
15,636 KB
testcase_15 AC 228 ms
15,796 KB
testcase_16 AC 141 ms
15,768 KB
testcase_17 AC 226 ms
15,780 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def ascan; gets.split.map(&:to_i); end
def scan; gets.to_i; end

require 'prime'

ll = ascan

@dp={}
def makeable(l,boards)
    return 0 if l==0
    key = [l]
    return @dp[key] if @dp[key]
    
    best = 9999
    boards.each{|b|
        next if l<b
        m = makeable(l-b, boards)
        return @dp[key]=false if !m
        best = [best,m].min
    }
    return @dp[key]=best+1
end

best = 5e15.to_i

1.upto(28){|a|
    (a+1).upto(29){|b|
        (b+1).upto(30){|c|
            @dp={}
            cost = 0
            x = [a,b,c]
            ll.each{|l|
                m = makeable(l,x)
                if !m
                    cost = nil; break
                end
                cost += m
            }
            best = [best,cost].min if cost
        }
    }
}

p best

0