結果
| 問題 |
No.3103 Butterfly Effect
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 18:41:01 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 568 bytes |
| コンパイル時間 | 306 ms |
| コンパイル使用メモリ | 82,172 KB |
| 実行使用メモリ | 67,020 KB |
| 最終ジャッジ日時 | 2025-06-12 18:41:17 |
| 合計ジャッジ時間 | 7,940 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | RE * 1 |
| other | RE * 50 |
ソースコード
n = int(input())
a = list(map(int, input().split()))
dp = [0] * (n + 1)
stack = []
for i in range(1, n + 1):
current = a[i - 1]
max_abs = abs(current)
best = dp[i - 1] + max_abs
start = i
while stack:
val, s, b = stack[-1]
if max_abs >= abs(val):
stack.pop()
candidate = b + (max_abs - abs(val)) * (i - s + 1)
if candidate > best:
best = candidate
start = s
else:
break
stack.append((current, start, best))
dp[i] = best
print(dp[n])
gew1fw