結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,228 KB
testcase_01 AC 75 ms
71,280 KB
testcase_02 AC 75 ms
71,516 KB
testcase_03 AC 73 ms
71,460 KB
testcase_04 AC 78 ms
71,132 KB
testcase_05 AC 73 ms
71,468 KB
testcase_06 AC 74 ms
71,424 KB
testcase_07 AC 76 ms
71,132 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 76 ms
71,340 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 75 ms
71,524 KB
testcase_21 AC 74 ms
71,336 KB
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][j] // a)
print(max(DP[n]))
0