結果
| 問題 |
No.297 カードの数式
|
| コンテスト | |
| ユーザー |
urutom
|
| 提出日時 | 2019-04-05 01:03:00 |
| 言語 | Ruby (3.4.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 449 bytes |
| コンパイル時間 | 257 ms |
| コンパイル使用メモリ | 7,296 KB |
| 実行使用メモリ | 12,288 KB |
| 最終ジャッジ日時 | 2024-12-29 12:55:03 |
| 合計ジャッジ時間 | 3,580 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 16 WA * 7 |
コンパイルメッセージ
Main.rb:1: warning: assigned but unused variable - n Main.rb:5: warning: assigned but unused variable - c 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