結果
問題 |
No.2458 Line Up Charged Balls
|
ユーザー |
![]() |
提出日時 | 2025-03-20 20:20:36 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,325 bytes |
コンパイル時間 | 199 ms |
コンパイル使用メモリ | 82,444 KB |
実行使用メモリ | 123,672 KB |
最終ジャッジ日時 | 2025-03-20 20:21:44 |
合計ジャッジ時間 | 4,659 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 7 WA * 18 |
ソースコード
n = int(input()) Q = list(map(int, input().split())) if n < 2: print(0) else: max_e = Q[0] * Q[1] dp_prev = max_e max_pos = -float('inf') max_pos_val = 0 min_neg = float('inf') min_neg_val = 0 if Q[1] > 0: max_pos = Q[1] max_pos_val = max(dp_prev, 0) else: min_neg = Q[1] min_neg_val = max(dp_prev, 0) for i in range(2, n): current_q = Q[i] candidate_prev = current_q * Q[i-1] candidate_cont = dp_prev + candidate_prev if current_q > 0: candidate = current_q * max_pos + max_pos_val if max_pos != -float('inf') else -float('inf') else: candidate = current_q * min_neg + min_neg_val if min_neg != float('inf') else -float('inf') current_dp = max(candidate, candidate_cont, candidate_prev) max_e = max(max_e, current_dp) max_contrib = max(current_dp, 0) if current_q > max_pos or (current_q == max_pos and max_contrib > max_pos_val): max_pos = current_q max_pos_val = max_contrib if current_q < min_neg or (current_q == min_neg and max_contrib > min_neg_val): min_neg = current_q min_neg_val = max_contrib dp_prev = current_dp print(max_e)