結果

問題 No.1084 積の積
ユーザー hedwig100hedwig100
提出日時 2020-06-19 23:01:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 135 ms / 2,000 ms
コード長 793 bytes
コンパイル時間 143 ms
コンパイル使用メモリ 82,032 KB
実行使用メモリ 86,272 KB
最終ジャッジ日時 2024-07-03 15:29:15
合計ジャッジ時間 3,098 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 9

def main():
    N = int(input())
    A = list(map(int,input().split()))

    if 0 in A:
        print(0)
        return

    r = 0
    now = 1
    cnt = [0] * (N + 1)
    for l in range(N):
        while r < N and now * A[r] < INF:
            now *= A[r]
            r += 1
        if l > 0:
            cnt[l - 1] -= r - l + 1
        if r > 0:
            cnt[r - 1] += 1
        if l > 1:
            cnt[l - 2] += r - l
        now //= A[l]

    for i in range(N - 1,-1,-1):
        cnt[i] += cnt[i + 1]
    for i in range(N - 1,-1,-1):
        cnt[i] += cnt[i + 1]

    ans = 1
    for i in range(N):
        ans *= pow(A[i],cnt[i],MOD)
        ans %= MOD
    print(ans)
  
if __name__ == '__main__':
    main()
0