結果

問題 No.10 +か×か
ユーザー らっしー(raccy)
提出日時 2015-01-30 21:49:02
言語 Ruby
(3.4.1)
結果
TLE  
実行時間 -
コード長 610 bytes
コンパイル時間 123 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 19,228 KB
最終ジャッジ日時 2024-06-23 04:28:19
合計ジャッジ時間 7,259 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 4 TLE * 1 -- * 7
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:26: warning: assigned but unused variable - n
Syntax OK

ソースコード

diff #

def calc(total, current, list, point)
  if point == list.size
    if total == current
      return ""
    else
      return nil
    end
  end
  # +
  next_current = current + list[point]
  if next_current <= total
    if next_calc = calc(total, next_current, list, point + 1)
      return "+" + next_calc
    end
  end
  # *
  next_current = current * list[point]
  if next_current <= total
    if next_calc = calc(total, next_current, list, point + 1)
      return "*" + next_calc
    end
  end
  return nil
end

n = gets.to_i
total = gets.to_i
list = gets.split.map &:to_i
puts calc(total, list[0], list, 1)
0