結果
| 問題 |
No.297 カードの数式
|
| コンテスト | |
| ユーザー |
tjake
|
| 提出日時 | 2015-12-19 15:24:06 |
| 言語 | Python2 (2.7.18) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 680 bytes |
| コンパイル時間 | 49 ms |
| コンパイル使用メモリ | 6,912 KB |
| 実行使用メモリ | 11,776 KB |
| 最終ジャッジ日時 | 2024-09-16 16:05:45 |
| 合計ジャッジ時間 | 2,810 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 1 TLE * 1 -- * 21 |
ソースコード
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
tjake