結果

問題 No.1084 積の積
ユーザー ayaoni
提出日時 2020-11-26 14:58:12
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 157 ms / 2,000 ms
コード長 858 bytes
コンパイル時間 240 ms
コンパイル使用メモリ 82,268 KB
実行使用メモリ 101,708 KB
最終ジャッジ日時 2024-07-23 20:49:54
合計ジャッジ時間 3,511 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from itertools import accumulate
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))


N = I()
A = LI()
mod = 10**9+7

if 0 in A:
    print(0)
    exit()

count = [0]*(N+2)
a = A[0]  # 区間[l,r)の積
l,r = 0,1
while r <= N:
    if a < 10**9:
        if r <= N-1:
            a *= A[r]
            r += 1
        else:
            count[l] += r-l
            count[l+1] -= r-l+1
            count[r+1] += 1
            if l < r:
                a //= A[l]
                l += 1
            else:
                break
    else:
        count[l] += r-l-1
        count[l+1] -= r-l
        count[r] += 1
        a //= A[l]
        l += 1

count = list(accumulate(list(accumulate(count))))
ans = 1
for i in range(N):
    ans *= pow(A[i],count[i],mod)
    ans %= mod

print(ans)
0