結果

問題 No.297 カードの数式
ユーザー yukiyuki
提出日時 2015-11-07 00:57:14
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 637 bytes
コンパイル時間 202 ms
コンパイル使用メモリ 11,292 KB
実行使用メモリ 15,436 KB
最終ジャッジ日時 2023-10-11 14:47:18
合計ジャッジ時間 4,021 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 RE -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 RE -
testcase_20 WA -
testcase_21 RE -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N = gets.to_i
cn,oprs = gets.split.group_by{|x| %w(+ -).include? x}.values

cn = cn.sort.reverse
oprs = oprs.sort
ansmax,ansmin = [0,0]

slot = oprs.size + 1
max = cn[0..(-slot)].join.to_i
ansmax = max
cn.last(slot-1).zip(oprs) do |c,opr|
  ansmax = opr.to_sym.to_proc.call(ansmax,c.to_i)
end

if oprs.last == "-"
  ansmin = -max
  oprs.pop
  oprs = oprs.reverse << "+"
  cn.last(slot-1).zip(oprs) do |c,opr|
    ansmin = opr.to_sym.to_proc.call(ansmin,c.to_i)
  end
else
  a = Array.new(slot){ "" }
  index = (0..slot-1).cycle
  cn.each{|c| i = index.next; a[i] = c + a[i]}
  ansmin = a.map(&:to_i).inject(:+)
end

puts [ansmax,ansmin]
0