結果

問題 No.505 カードの数式2
ユーザー h_noson
提出日時 2017-06-13 23:43:23
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 571 bytes
コンパイル時間 82 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-09-24 17:04:18
合計ジャッジ時間 1,981 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 7 WA * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
a = list(map(int,input().split(' ')))

i = 0
while i < n and a[i] == 0: i += 1
if i == n:
    print(0)
    exit(0)
ans = abs(a[i])
i += 1
sign = 0
for x in a[i:]:
    sign ^= x < 0
if sign == 0:
    for x in a[i:]:
        if x in [0,1]:
            ans += x
        else:
            ans *= x
else:
    mx = -10 ** 9
    for x in a[i:]:
        if x < 0:
            mx = max(mx,x)
    for x in a[i:]:
        if x in [0,1]:
            ans += x
        elif x == mx:
            ans -= x
            mx = 0
        else:
            ans *= x
print(ans)
0