結果

問題 No.297 カードの数式
ユーザー urutomurutom
提出日時 2019-04-05 01:03:00
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 449 bytes
コンパイル時間 36 ms
コンパイル使用メモリ 11,588 KB
実行使用メモリ 15,368 KB
最終ジャッジ日時 2023-08-28 13:11:20
合計ジャッジ時間 3,363 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
15,292 KB
testcase_01 AC 78 ms
15,068 KB
testcase_02 AC 80 ms
15,052 KB
testcase_03 AC 79 ms
15,116 KB
testcase_04 AC 79 ms
15,092 KB
testcase_05 AC 79 ms
15,288 KB
testcase_06 WA -
testcase_07 AC 78 ms
15,272 KB
testcase_08 AC 80 ms
15,164 KB
testcase_09 AC 78 ms
15,312 KB
testcase_10 AC 79 ms
15,092 KB
testcase_11 AC 77 ms
15,128 KB
testcase_12 AC 78 ms
15,064 KB
testcase_13 AC 78 ms
15,300 KB
testcase_14 AC 78 ms
15,284 KB
testcase_15 AC 78 ms
15,152 KB
testcase_16 AC 78 ms
15,248 KB
testcase_17 AC 80 ms
15,308 KB
testcase_18 AC 80 ms
15,252 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 79 ms
15,108 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:1: warning: assigned but unused variable - n
Main.rb:5: warning: assigned but unused variable - c
Syntax OK

ソースコード

diff #

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]*" "
0