結果

問題 No.505 カードの数式2
ユーザー hedwig100hedwig100
提出日時 2020-05-31 16:03:35
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 955 bytes
コンパイル時間 231 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 76,160 KB
最終ジャッジ日時 2024-04-28 20:25:20
合計ジャッジ時間 13,486 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,068 KB
testcase_01 AC 48 ms
62,312 KB
testcase_02 AC 992 ms
75,588 KB
testcase_03 AC 38 ms
52,064 KB
testcase_04 AC 38 ms
52,352 KB
testcase_05 AC 42 ms
52,352 KB
testcase_06 AC 41 ms
52,224 KB
testcase_07 AC 43 ms
52,352 KB
testcase_08 AC 41 ms
52,096 KB
testcase_09 WA -
testcase_10 AC 41 ms
52,224 KB
testcase_11 WA -
testcase_12 AC 42 ms
52,736 KB
testcase_13 AC 42 ms
52,608 KB
testcase_14 AC 42 ms
52,560 KB
testcase_15 AC 42 ms
52,224 KB
testcase_16 AC 45 ms
52,352 KB
testcase_17 WA -
testcase_18 AC 41 ms
52,352 KB
testcase_19 AC 55 ms
61,056 KB
testcase_20 AC 64 ms
66,096 KB
testcase_21 AC 1,015 ms
76,032 KB
testcase_22 AC 983 ms
75,648 KB
testcase_23 AC 1,004 ms
75,272 KB
testcase_24 AC 1,006 ms
75,676 KB
testcase_25 AC 1,012 ms
75,620 KB
testcase_26 AC 981 ms
75,648 KB
testcase_27 AC 990 ms
75,648 KB
testcase_28 AC 981 ms
76,160 KB
testcase_29 WA -
testcase_30 AC 974 ms
75,548 KB
testcase_31 AC 981 ms
75,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

from itertools import permutations,product,combinations_with_replacement,groupby,accumulate,combinations
def main():
    N = int(input())
    A = list(map(int,input().split()))
    
    ans = -INF
    for L in product((0,1,2),repeat = N - 2):
        ret = A[0]
        for i in range(N - 2):
            if L[i] == 0:
                ret += A[i + 1]
            elif L[i] == 1:
                ret -= A[i + 1]
            else:
                ret *= A[i + 1]
        if ret < 0 and A[-1] < 0:
            ret = max(ret * A[-1],ret - A[-1])
        elif ret < 0 and A[-1] > 0:
            ret += A[-1]
        elif ret > 0 and A[-1] < 0:
            ret -= A[-1]
        elif ret > 0 and A[-1] > 0:
            ret = max(ret + A[-1],ret * A[-1])
        elif ret == 0:
            ret = abs(A[-1])
        ans = max(ans,ret)
    print(ans)
if __name__ == '__main__':
    main()
0