結果
| 問題 | No.297 カードの数式 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-11-07 01:01:33 |
| 言語 | Ruby (4.0.2) |
| 結果 |
AC
|
| 実行時間 | 96 ms / 1,000 ms |
| コード長 | 663 bytes |
| 記録 | |
| コンパイル時間 | 63 ms |
| コンパイル使用メモリ | 8,960 KB |
| 実行使用メモリ | 14,848 KB |
| 最終ジャッジ日時 | 2026-05-31 20:18:57 |
| 合計ジャッジ時間 | 2,947 ms |
|
ジャッジサーバーID (参考情報) |
judge1_1 / judge3_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 23 |
コンパイルメッセージ
Syntax OK
ソースコード
N = gets.to_i
C = gets.split.group_by{|x| %w(+ -).include? x}
oprs = C[true]
cn = C[false]
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].join(" ")