結果

問題 No.297 カードの数式
ユーザー cormorancormoran
提出日時 2016-06-07 18:07:55
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 743 bytes
コンパイル時間 108 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-04-17 05:47:03
合計ジャッジ時間 1,683 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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