結果
| 問題 |
No.1334 Multiply or Add
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 15:50:59 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 893 bytes |
| コンパイル時間 | 202 ms |
| コンパイル使用メモリ | 82,600 KB |
| 実行使用メモリ | 104,804 KB |
| 最終ジャッジ日時 | 2025-06-12 15:51:08 |
| 合計ジャッジ時間 | 8,448 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 12 WA * 59 |
ソースコード
MOD = 10**9 + 7
n = int(input())
a = list(map(int, input().split()))
if n == 0:
print(0)
else:
prev_sum_split = 0
prev_product_split = 0
prev_sum_not_split = 0
prev_product_not_split = a[0] % MOD
for i in range(1, n):
current = a[i] % MOD
new_sum_split = (prev_sum_not_split + prev_product_not_split) % MOD
new_product_split = current
new_sum_not_split = prev_sum_not_split
new_product_not_split = (prev_product_not_split * current) % MOD
# Update for next iteration
prev_sum_split, prev_product_split = new_sum_split, new_product_split
prev_sum_not_split, prev_product_not_split = new_sum_not_split, new_product_not_split
option1 = (prev_sum_split + prev_product_split) % MOD
option2 = (prev_sum_not_split + prev_product_not_split) % MOD
final = max(option1, option2)
print(final)
gew1fw