結果

問題 No.10 +か×か
ユーザー LaLa
提出日時 2021-01-07 10:39:16
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 351 bytes
コンパイル時間 213 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 206,976 KB
最終ジャッジ日時 2024-04-25 12:46:49
合計ジャッジ時間 7,268 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
12,288 KB
testcase_01 AC 76 ms
12,160 KB
testcase_02 AC 78 ms
12,160 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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][y]+"+" if y+a[x]<=t && dp[x+1][y+a[x]]<dp[x][y]+"+"
    dp[x+1][y*a[x]]=dp[x][y]+"*" if y*a[x]<=t && dp[x+1][y*a[x]]<dp[x][y]+"*"
  end
end

puts dp[n][t]
0