結果
| 問題 | No.505 カードの数式2 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2017-05-21 14:51:57 | 
| 言語 | Ruby (3.4.1) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 91 ms / 2,000 ms | 
| コード長 | 401 bytes | 
| コンパイル時間 | 261 ms | 
| コンパイル使用メモリ | 7,424 KB | 
| 実行使用メモリ | 12,288 KB | 
| 最終ジャッジ日時 | 2024-11-14 07:26:54 | 
| 合計ジャッジ時間 | 4,198 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 29 | 
コンパイルメッセージ
Syntax OK
ソースコード
def div(a, b)
  if b.zero?
    nil
  elsif a.positive?
    a / b
  else
    - (-a / b)
  end
end
n = gets.to_i
xs = gets.chomp.split.map(&:to_i)
mn = xs[0]
mx = xs[0]
(1...n).each do |i|
  x = xs[i]
  ys = []
  ys << mn + x
  ys << mn - x
  ys << mn * x
  ys << mx + x
  ys << mx - x
  ys << mx * x
  r = div(mx, x)
  ys << r if r
  r = div(mn, x)
  ys << r if r
  mn = ys.min
  mx = ys.max
end
p mx
            
            
            
        