結果

問題 No.505 カードの数式2
ユーザー sue_charosue_charo
提出日時 2017-04-22 11:24:04
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 1,450 bytes
コンパイル時間 135 ms
コンパイル使用メモリ 11,040 KB
実行使用メモリ 10,104 KB
最終ジャッジ日時 2023-08-09 02:05:47
合計ジャッジ時間 2,686 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
9,956 KB
testcase_01 AC 30 ms
10,040 KB
testcase_02 AC 30 ms
9,992 KB
testcase_03 AC 31 ms
10,016 KB
testcase_04 AC 31 ms
9,904 KB
testcase_05 AC 32 ms
10,040 KB
testcase_06 AC 31 ms
10,056 KB
testcase_07 AC 30 ms
10,104 KB
testcase_08 AC 30 ms
10,024 KB
testcase_09 AC 32 ms
9,968 KB
testcase_10 AC 30 ms
9,900 KB
testcase_11 AC 31 ms
9,992 KB
testcase_12 AC 30 ms
9,900 KB
testcase_13 AC 30 ms
9,992 KB
testcase_14 AC 31 ms
9,896 KB
testcase_15 AC 30 ms
9,972 KB
testcase_16 AC 30 ms
9,916 KB
testcase_17 AC 30 ms
9,928 KB
testcase_18 AC 31 ms
10,040 KB
testcase_19 AC 30 ms
9,992 KB
testcase_20 AC 30 ms
10,072 KB
testcase_21 AC 30 ms
10,048 KB
testcase_22 AC 30 ms
9,964 KB
testcase_23 AC 30 ms
10,040 KB
testcase_24 AC 30 ms
10,104 KB
testcase_25 AC 30 ms
9,988 KB
testcase_26 AC 30 ms
9,992 KB
testcase_27 AC 30 ms
9,968 KB
testcase_28 AC 30 ms
10,044 KB
testcase_29 AC 29 ms
9,984 KB
testcase_30 AC 30 ms
9,904 KB
testcase_31 AC 29 ms
9,908 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# coding: utf-8
import array, bisect, collections, heapq, itertools, math, random, re, string, sys, time
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7
 
 
def II(): return int(input())
def ILI(): return list(map(int, input().split()))
def IAI(LINE): return [ILI() for __ in range(LINE)]
def IDI(): return {key: value for key, value in ILI()}
 
 
def solve(N, a):
    dp = [[None] * 2 for i in range(N)]
    dp[0][0] = a[0]
    dp[0][1] = a[0]
    for i in range(1, N):
        now_num = a[i]
        if now_num == 0:
            dp[i][0] = min(dp[i - 1][0], 0)
            dp[i][1] = max(dp[i - 1][1], 0)
        else:
            next_list = [dp[i - 1][0] + now_num,
                         dp[i - 1][0] - now_num,
                         dp[i - 1][0] * now_num,
                         dp[i - 1][0] // now_num,
                         dp[i - 1][1] + now_num,
                         dp[i - 1][1] - now_num,
                         dp[i - 1][1] * now_num,
                         dp[i - 1][1] // now_num]
            if next_list[2] < 0:
                next_list[3] = math.ceil(dp[i - 1][0] / now_num)
            if next_list[6] < 0:
                next_list[7] = math.ceil(dp[i - 1][1] / now_num)

            dp[i][0] = min(next_list)
            dp[i][1] = max(next_list)

    ans = dp[N - 1][1]

    return ans


def main():
    N = II()
    a = ILI()
    print(solve(N, a))
 
 
if __name__ == "__main__":
    main()
0