結果

問題 No.297 カードの数式
ユーザー tjaketjake
提出日時 2015-12-19 15:24:06
言語 Python2
(2.7.18)
結果
TLE  
実行時間 -
コード長 680 bytes
コンパイル時間 68 ms
コンパイル使用メモリ 6,728 KB
実行使用メモリ 10,732 KB
最終ジャッジ日時 2023-10-14 22:27:24
合計ジャッジ時間 3,105 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
10,732 KB
testcase_01 AC 12 ms
6,112 KB
testcase_02 AC 12 ms
6,212 KB
testcase_03 AC 15 ms
6,272 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import permutations
n = input()
c = raw_input().split()
mi = 10**9
ma = -10**9
for p in permutations(c):
    # filter
    if p[0] in "+-" or p[-1] in "+-":
        continue
    ok = 1
    for i in range(n-1):
        if p[i] in "+-" and p[i+1] in "+-":
            ok = 0
            break
    if not ok: continue
    tmp = 0
    op = "+"
    res = 0
    for e in p:
        if e in "+-":
            if op is "+": res += tmp
            if op is "-": res -= tmp
            op = e
            tmp = 0
        else:
            tmp = 10*tmp + int(e)
    if op is "+": res += tmp
    if op is "-": res -= tmp
    mi = min(mi, res)
    ma = max(ma, res)
print ma, mi
0