結果

問題 No.297 カードの数式
ユーザー roiti46roiti46
提出日時 2015-12-09 19:06:58
言語 Python2
(2.7.18)
結果
AC  
実行時間 25 ms / 1,000 ms
コード長 749 bytes
コンパイル時間 44 ms
コンパイル使用メモリ 6,476 KB
実行使用メモリ 7,944 KB
最終ジャッジ日時 2023-08-26 22:50:31
合計ジャッジ時間 1,921 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
7,836 KB
testcase_01 AC 22 ms
7,884 KB
testcase_02 AC 21 ms
7,944 KB
testcase_03 AC 22 ms
7,744 KB
testcase_04 AC 21 ms
7,744 KB
testcase_05 AC 22 ms
7,736 KB
testcase_06 AC 21 ms
7,944 KB
testcase_07 AC 22 ms
7,736 KB
testcase_08 AC 25 ms
7,740 KB
testcase_09 AC 21 ms
7,740 KB
testcase_10 AC 21 ms
7,932 KB
testcase_11 AC 21 ms
7,908 KB
testcase_12 AC 22 ms
7,912 KB
testcase_13 AC 21 ms
7,928 KB
testcase_14 AC 21 ms
7,824 KB
testcase_15 AC 21 ms
7,820 KB
testcase_16 AC 22 ms
7,736 KB
testcase_17 AC 21 ms
7,772 KB
testcase_18 AC 21 ms
7,912 KB
testcase_19 AC 22 ms
7,768 KB
testcase_20 AC 21 ms
7,732 KB
testcase_21 AC 21 ms
7,832 KB
testcase_22 AC 24 ms
7,944 KB
testcase_23 AC 22 ms
7,736 KB
testcase_24 AC 21 ms
7,740 KB
testcase_25 AC 21 ms
7,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# -*- coding: utf-8 -*-
import sys,copy,math,heapq,itertools as it,fractions,re,bisect,collections as coll

n = int(raw_input())
a = raw_input().split()

x = ""
p = m = 0
for c in a:
    if c == "+": p += 1
    elif c == "-": m += 1
    else: x += c

x = sorted(x, reverse = True)
y = x[:]
nums = []
for i in xrange(p + m):
    nums.append(int(x.pop()))
nums.append(int("".join(x)))
nums = nums[::-1]

mx = nums[0]
mn = nums[-1]
for i in xrange(p + m):
    if i < p:
        mx += nums[i + 1]
        mn += nums[-i - 2]
    else:
        mx -= nums[i + 1]
        mn -= nums[-i - 2]
if m == 0:
    nums = [""] * (p + 1)
    i = 0
    while y:
        nums[i%(p+1)] = y.pop(0) + nums[i%(p+1)]
        i += 1
    mn = sum(map(int, nums))
print mx, mn
0