結果

問題 No.297 カードの数式
コンテスト
ユーザー tjake
提出日時 2015-12-19 15:24:06
言語 PyPy2
(7.3.20)
結果
TLE  
実行時間 -
コード長 680 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 119 ms
コンパイル使用メモリ 77,728 KB
最終ジャッジ日時 2025-12-03 18:43:25
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 1 TLE * 1 -- * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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