結果

問題 No.297 カードの数式
ユーザー 👑 rin204rin204
提出日時 2022-07-14 13:13:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 71 ms / 1,000 ms
コード長 720 bytes
コンパイル時間 468 ms
コンパイル使用メモリ 87,268 KB
実行使用メモリ 71,588 KB
最終ジャッジ日時 2023-09-08 03:13:39
合計ジャッジ時間 3,607 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,400 KB
testcase_01 AC 67 ms
71,240 KB
testcase_02 AC 69 ms
71,356 KB
testcase_03 AC 69 ms
71,320 KB
testcase_04 AC 69 ms
71,232 KB
testcase_05 AC 68 ms
71,288 KB
testcase_06 AC 66 ms
71,248 KB
testcase_07 AC 69 ms
71,348 KB
testcase_08 AC 68 ms
71,440 KB
testcase_09 AC 68 ms
71,440 KB
testcase_10 AC 68 ms
71,504 KB
testcase_11 AC 69 ms
71,112 KB
testcase_12 AC 67 ms
71,272 KB
testcase_13 AC 66 ms
71,424 KB
testcase_14 AC 68 ms
71,232 KB
testcase_15 AC 68 ms
71,408 KB
testcase_16 AC 67 ms
71,512 KB
testcase_17 AC 67 ms
71,388 KB
testcase_18 AC 71 ms
71,376 KB
testcase_19 AC 71 ms
71,232 KB
testcase_20 AC 69 ms
71,244 KB
testcase_21 AC 70 ms
71,232 KB
testcase_22 AC 71 ms
71,588 KB
testcase_23 AC 70 ms
71,348 KB
testcase_24 AC 69 ms
71,228 KB
testcase_25 AC 71 ms
71,308 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
C = input().split()
p = 0
m = 0
A = []
for c in C:
    if c == "+":
        p += 1
    elif c == "-":
        m += 1
    else:
        A.append(int(c))
A.sort()
le = p + m + 1
if m > 0:
    while len(A) > le:
        a = A.pop()
        A[-1] += 10 * a

    tot = sum(A)
    ma = tot - 2 * sum(A[:m])
    A = A[::-1]
    mi = tot - 2 * sum(A[:m])
    print(ma, mi)
else:
    B = A[:]
    while len(A) > le:
        a = A.pop()
        A[-1] += 10 * a

    tot = sum(A)
    ma = tot - 2 * sum(A[:m])

    A = B
    A = A[::-1]
    times = 1
    cnt = 0
    mi = 0
    for a in A:
        mi += a * times
        cnt += 1
        if cnt == le:
            cnt = 0
            times *= 10
    print(ma, mi)
0