結果

問題 No.10 +か×か
コンテスト
ユーザー らっしー(raccy)
提出日時 2015-01-30 21:49:02
言語 Ruby
(4.0.2)
コンパイル:
ruby -w -c _filename_
実行:
ruby _filename_
結果
TLE  
実行時間 -
コード長 610 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 373 ms
コンパイル使用メモリ 8,704 KB
実行使用メモリ 14,464 KB
最終ジャッジ日時 2026-07-27 15:07:50
合計ジャッジ時間 7,499 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 4 TLE * 1 -- * 8
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:26: warning: assigned but unused variable - n
Syntax OK

ソースコード

diff #
raw source code

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