結果
| 問題 | No.297 カードの数式 |
| コンテスト | |
| ユーザー |
urutom
|
| 提出日時 | 2019-04-05 01:03:00 |
| 言語 | Ruby (4.0.2) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 449 bytes |
| 記録 | |
| コンパイル時間 | 41 ms |
| コンパイル使用メモリ | 8,960 KB |
| 実行使用メモリ | 14,976 KB |
| 最終ジャッジ日時 | 2026-06-03 07:31:05 |
| 合計ジャッジ時間 | 3,019 ms |
|
ジャッジサーバーID (参考情報) |
judge2_1 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 16 WA * 7 |
コンパイルメッセージ
Main.rb:5: warning: assigned but unused variable - c Main.rb:1: warning: assigned but unused variable - n Syntax OK
ソースコード
n=gets.to_i
plus=0
minus=0
fig=[]
c=gets.split.each{|c|
if c==?+
plus+=1
elsif c==?-
minus+=1
else
fig << c.to_i
end
}
max=min=0
max_fig=fig.sort.reverse
minus.times{max-=max_fig.pop}
plus.times{max+=max_fig.pop}
max+=max_fig.join.to_i
if minus==0
min=max
else
min_fig=fig.sort
min=min_fig.shift
plus.times{min+=min_fig.shift}
(minus-1).times{min-=min_fig.shift}
min-=min_fig.reverse.join.to_i
end
puts [max,min]*" "
urutom