結果
| 問題 |
No.1334 Multiply or Add
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 16:20:25 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,199 bytes |
| コンパイル時間 | 393 ms |
| コンパイル使用メモリ | 82,020 KB |
| 実行使用メモリ | 268,808 KB |
| 最終ジャッジ日時 | 2025-06-12 16:20:36 |
| 合計ジャッジ時間 | 9,139 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 46 WA * 4 TLE * 1 -- * 20 |
ソースコード
MOD = 10**9 + 7
n = int(input())
A = list(map(int, input().split()))
groups = []
i = 0
while i < n:
# Skip leading 1s
while i < n and A[i] == 1:
groups.append(1)
i += 1
if i >= n:
break
# Find the next number >1 after i
j = i + 1
while j < n and A[j] == 1:
j += 1
if j < n and A[j] > 1:
# There are at least two numbers >1, start forming a group
k = j
while True:
# Look for the next number >1 after k
l = k + 1
while l < n and A[l] == 1:
l += 1
if l < n and A[l] > 1:
k = l
else:
break
# Group from i to k inclusive
group = A[i:k+1]
product = 1
sum_group = 0
for num in group:
product *= num
sum_group += num
if product >= sum_group:
groups.append(product % MOD)
else:
for num in group:
groups.append(num % MOD)
i = k + 1
else:
# Only one number >1 in this segment
groups.append(A[i] % MOD)
i += 1
total = sum(groups) % MOD
print(total)
gew1fw