結果

問題 No.297 カードの数式
ユーザー しらっ亭
提出日時 2015-11-07 13:46:57
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 41 ms / 1,000 ms
コード長 790 bytes
コンパイル時間 682 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-12-26 02:23:48
合計ジャッジ時間 2,138 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve():
    N = int(input())
    C = input().split()

    np = nm = 0
    I = []
    for c in C:
        if c == '+':
            np += 1
        elif c == '-':
            nm += 1
        else:
            I += c
    I.sort()

    J = []

    for i in range(np + nm):
        J.append(int(I[i]))

    J.append(int(''.join(I[np + nm:][::-1])))

    K = J[::-1]

    mi = ma = 0
    for i in range(np + 1):
        mi += J[i]
        ma += K[i]
    for i in range(np + 1, np + nm + 1):
        mi -= J[i]
        ma -= K[i]

    if nm == 0:
        ns = [[] for i in range(np + 1)]
        for i in range(len(I)):
            ns[i % (np + 1)].append(I[i])
        mi = 0
        for n in ns:
            mi += int(''.join(n))

    print(ma, mi)


if __name__ == '__main__':
    solve()
0