結果

問題 No.297 カードの数式
ユーザー cormoran
提出日時 2016-06-07 18:07:55
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 743 bytes
コンパイル時間 325 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-10-08 17:32:20
合計ジャッジ時間 2,048 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16 WA * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
import math
N = int(input())
C = input().split()
ops = {'+' : 0, '-' : 0}
op = 0
nums = [0] * 10
for c in C:
    if c in ops:
        ops[c] += 1
        op += 1
    else :
        nums[int(c)] += 1
num = N - op

numbers = [0] * (op + 1)
pos = 0
for i in range(op):
    while nums[pos] == 0 :
        pos += 1
    numbers[i] = pos
    nums[pos] -= 1
# 最大
a = 1
while True:
    while pos < 10 and nums[pos] == 0 :
        pos += 1
    if pos >= 10 :
        break
    numbers[-1] += pos * a
    nums[pos] -= 1
    a *= 10
numbers.reverse()
#print(numbers)
max_ans = sum(numbers[:(ops['+'] + 1)]) - sum(numbers[(ops['+'] + 1):])
min_ans = - sum(numbers[:ops['-']]) + sum(numbers[(ops['-']):])

print(max_ans, min_ans)
0