結果

問題 No.505 カードの数式2
ユーザー lloyzlloyz
提出日時 2022-11-12 01:15:26
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 530 bytes
コンパイル時間 391 ms
コンパイル使用メモリ 86,864 KB
実行使用メモリ 71,652 KB
最終ジャッジ日時 2023-10-11 19:06:37
合計ジャッジ時間 4,439 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 72 ms
71,260 KB
testcase_02 AC 73 ms
71,356 KB
testcase_03 AC 73 ms
71,356 KB
testcase_04 AC 72 ms
71,404 KB
testcase_05 AC 73 ms
71,256 KB
testcase_06 AC 72 ms
71,280 KB
testcase_07 AC 72 ms
71,388 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 74 ms
71,304 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
A = list(map(int, input().split()))

INF = 10**18
DP = [[0 for _ in range(4)] for _ in range(n + 1)]
for i in range(n):
    a = A[i]
    for j in range(4):
        if DP[i][j] == -INF:
            continue
        DP[i + 1][0] = max(DP[i + 1][0], DP[i][j] + a)
        DP[i + 1][1] = max(DP[i + 1][1], DP[i][j] - a)
        DP[i + 1][2] = max(DP[i + 1][2], DP[i][j] * a)
        if a == 0:
            DP[i + 1][3] = -INF
        else:
            DP[i + 1][3] = max(DP[i + 1][3], DP[i][3] // a)
print(max(DP[n]))
0