結果

問題 No.297 カードの数式
ユーザー roiti46roiti46
提出日時 2015-12-09 19:04:43
言語 Python2
(2.7.18)
結果
RE  
実行時間 -
コード長 744 bytes
コンパイル時間 70 ms
コンパイル使用メモリ 6,720 KB
実行使用メモリ 7,980 KB
最終ジャッジ日時 2023-10-13 08:43:49
合計ジャッジ時間 1,754 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 23 ms
7,776 KB
testcase_02 AC 24 ms
7,940 KB
testcase_03 RE -
testcase_04 AC 24 ms
7,744 KB
testcase_05 AC 23 ms
7,940 KB
testcase_06 RE -
testcase_07 AC 23 ms
7,896 KB
testcase_08 AC 23 ms
7,792 KB
testcase_09 AC 23 ms
7,736 KB
testcase_10 AC 23 ms
7,732 KB
testcase_11 AC 22 ms
7,912 KB
testcase_12 AC 23 ms
7,736 KB
testcase_13 AC 22 ms
7,744 KB
testcase_14 AC 22 ms
7,776 KB
testcase_15 AC 23 ms
7,764 KB
testcase_16 AC 23 ms
7,764 KB
testcase_17 AC 24 ms
7,900 KB
testcase_18 AC 23 ms
7,860 KB
testcase_19 WA -
testcase_20 AC 23 ms
7,828 KB
testcase_21 WA -
testcase_22 AC 23 ms
7,912 KB
testcase_23 AC 23 ms
7,768 KB
testcase_24 AC 23 ms
7,796 KB
testcase_25 AC 23 ms
7,792 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

y = x = sorted(x, reverse = True)
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