結果

問題 No.297 カードの数式
ユーザー rlangevinrlangevin
提出日時 2024-01-18 00:23:50
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 711 bytes
コンパイル時間 4,004 ms
コンパイル使用メモリ 81,444 KB
実行使用メモリ 53,460 KB
最終ジャッジ日時 2024-01-18 00:24:03
合計ジャッジ時間 3,144 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
53,460 KB
testcase_01 AC 45 ms
53,460 KB
testcase_02 AC 41 ms
53,460 KB
testcase_03 AC 41 ms
53,460 KB
testcase_04 AC 42 ms
53,460 KB
testcase_05 AC 41 ms
53,460 KB
testcase_06 AC 41 ms
53,460 KB
testcase_07 AC 42 ms
53,460 KB
testcase_08 AC 41 ms
53,460 KB
testcase_09 AC 41 ms
53,460 KB
testcase_10 WA -
testcase_11 AC 40 ms
53,460 KB
testcase_12 AC 40 ms
53,460 KB
testcase_13 AC 40 ms
53,460 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 41 ms
53,460 KB
testcase_19 AC 40 ms
53,460 KB
testcase_20 AC 41 ms
53,460 KB
testcase_21 AC 40 ms
53,460 KB
testcase_22 WA -
testcase_23 AC 40 ms
53,460 KB
testcase_24 AC 41 ms
53,460 KB
testcase_25 AC 41 ms
53,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from copy import *

N = int(input())
C = list(input().split())
A = []
p, m = 0, 0
for c in C:
    if c == "+":
        p += 1
    elif c == "-":
        m += 1
    else:
        A.append(int(c))

B = deepcopy(A)
ma = 0
A.sort(reverse=True)
for i in range(m):
    ma -= A.pop()
for i in range(p):
    ma += A.pop()
v = ""
for a in A:
    v += str(a)
ma += int(v)

mi = 0
B.sort(reverse=True)
if m:
    p += 1
    for i in range(m-1):
        mi -= B.pop()
    for i in range(p):
        mi += B.pop()
    v = ""
    for b in B:
        v += str(b)
    mi -= int(v)
else:
    S = [""] * (p + 1)
    for i in range(len(B)):
        S[i%(p+1)] += str(B[-1-i])
    for s in S:
        mi += int(s)
    
print(ma, mi)
0