結果

問題 No.10 +か×か
ユーザー LaLa
提出日時 2021-01-07 10:41:56
言語 Ruby
(3.2.2)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 330 bytes
コンパイル時間 43 ms
コンパイル使用メモリ 11,336 KB
実行使用メモリ 279,844 KB
最終ジャッジ日時 2023-08-21 06:33:11
合計ジャッジ時間 15,726 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
15,280 KB
testcase_01 AC 81 ms
15,176 KB
testcase_02 AC 83 ms
15,076 KB
testcase_03 TLE -
testcase_04 AC 677 ms
42,932 KB
testcase_05 AC 81 ms
15,164 KB
testcase_06 TLE -
testcase_07 AC 1,746 ms
103,048 KB
testcase_08 AC 416 ms
35,128 KB
testcase_09 AC 570 ms
36,516 KB
testcase_10 AC 81 ms
15,464 KB
testcase_11 AC 81 ms
15,272 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

n=gets.to_i
t=gets.to_i
a=gets.split.map(&:to_i)
dp=Array.new(n+1){Array.new(t+1,"!")}
dp[1][a[0]]=""

(1...n).each do |x|
  (0..t).each do |y|
    next if dp[x][y]=="!"
    dp[x+1][y+a[x]]=[dp[x+1][y+a[x]],dp[x][y]+"+"].max if y+a[x]<=t
    dp[x+1][y*a[x]]=[dp[x+1][y*a[x]],dp[x][y]+"*"].max if y*a[x]<=t
  end
end

puts dp[n][t]
0