結果

問題 No.297 カードの数式
ユーザー TANIGUCHI KousukeTANIGUCHI Kousuke
提出日時 2015-11-07 23:41:22
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 858 bytes
コンパイル時間 40 ms
コンパイル使用メモリ 11,536 KB
実行使用メモリ 15,404 KB
最終ジャッジ日時 2023-10-11 15:16:08
合計ジャッジ時間 3,333 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
15,164 KB
testcase_01 AC 85 ms
15,284 KB
testcase_02 AC 82 ms
15,248 KB
testcase_03 AC 80 ms
15,060 KB
testcase_04 AC 82 ms
15,252 KB
testcase_05 AC 80 ms
15,068 KB
testcase_06 WA -
testcase_07 AC 81 ms
15,052 KB
testcase_08 AC 79 ms
15,252 KB
testcase_09 AC 81 ms
15,372 KB
testcase_10 AC 83 ms
15,048 KB
testcase_11 AC 79 ms
15,076 KB
testcase_12 AC 78 ms
15,152 KB
testcase_13 AC 79 ms
15,084 KB
testcase_14 AC 80 ms
15,104 KB
testcase_15 AC 79 ms
15,308 KB
testcase_16 AC 81 ms
15,256 KB
testcase_17 AC 81 ms
15,108 KB
testcase_18 AC 80 ms
15,048 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 79 ms
15,348 KB
testcase_22 AC 79 ms
15,256 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:36: warning: assigned but unused variable - n
Syntax OK

ソースコード

diff #

OP= "+-"
def max(s)
    op = s.take_while {|c| OP.include?(c) }
    num = s.drop(op.size).reverse
    v = []
    until op.empty?
        pm = op.pop
        n = num.pop
        v.unshift( (pm+n).to_i )
    end
    v.unshift(num.join().to_i)
    v.inject(0,&:+)
end

def min(s)
    op = s.take_while {|c| OP.include?(c) }.reverse
    num = s.drop(op.size).reverse
    if op.first == '-'
        op.shift
        op.push('+')
        v = []
        until op.empty?
            pm = op.pop
            n = num.pop
            v.unshift( (pm + n).to_i )
        end
        v.unshift(num.join().to_i * -1)
        v.inject(0,&:+)
    else
        mins = Array.new(op.size + 1,"")
        num.each_with_index {|v, i| mins[i % mins.size] += v }
        mins.map(&:to_i).inject(0,&:+)
    end
end

n = gets.to_i
s = gets.split.sort

puts [max(s), min(s)].join(" ")
0