結果

問題 No.297 カードの数式
ユーザー steek79steek79
提出日時 2015-11-07 23:03:58
言語 Python2
(2.7.18)
結果
WA  
実行時間 -
コード長 1,248 bytes
コンパイル時間 260 ms
コンパイル使用メモリ 6,668 KB
実行使用メモリ 6,188 KB
最終ジャッジ日時 2023-10-11 15:15:45
合計ジャッジ時間 1,812 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
5,944 KB
testcase_01 AC 12 ms
6,128 KB
testcase_02 AC 11 ms
5,956 KB
testcase_03 AC 11 ms
6,076 KB
testcase_04 AC 12 ms
6,040 KB
testcase_05 AC 11 ms
6,000 KB
testcase_06 WA -
testcase_07 AC 12 ms
5,956 KB
testcase_08 AC 12 ms
6,128 KB
testcase_09 AC 12 ms
6,024 KB
testcase_10 RE -
testcase_11 RE -
testcase_12 AC 12 ms
6,024 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 AC 11 ms
6,188 KB
testcase_19 AC 11 ms
5,960 KB
testcase_20 AC 11 ms
6,108 KB
testcase_21 AC 11 ms
6,008 KB
testcase_22 RE -
testcase_23 AC 11 ms
6,028 KB
testcase_24 AC 11 ms
6,004 KB
testcase_25 AC 11 ms
6,012 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/python
# -*- coding: utf-8 -*-
N = input()
inputs = raw_input().split()

numbers = []
symbols = []
for n in inputs:
    if n.isdigit():
        numbers.append(n)
    else:
        symbols.append(n)

numbers = map(int, numbers)

s_numbers = sorted(numbers, reverse=True) # [5,4,3,2,1]
smalls = []
for loop in xrange(len(symbols)):
    smalls.append(s_numbers.pop()) #small numbers
str_numbers = map(str, s_numbers)
big = ''.join(str_numbers)
big = int(big) #biggest number possible

n_plus = symbols.count('+')
n_minus = symbols.count('-')

BIG = big
big_smalls = smalls
for n in xrange(n_plus):
    BIG += big_smalls.pop()
for n in xrange(n_minus):
    BIG -= big_smalls.pop()

if n_minus > 0:
    SMALL = 0
    sma_smalls = smalls
    sma_smalls.append(BIG)
    for n in xrange(n_minus):
        SMALL -= sma_smalls.pop()
    for n in xrange(n_plus):
        SMALL += sma_smalls.pop()

elif n_minus == 0: #ここから解説見た
    smalls = [[] for loop in xrange(n_plus+1)]
    for i in xrange(len(numbers)):
        smalls[i%len(smalls)].append(numbers[i])
    smalls = map(sorted, smalls)

    SMALL = 0
    for lst in smalls:
        lst = [str(n) for n in lst]
        n = int(''.join(lst))
        SMALL += n

print BIG, SMALL
0