結果

問題 No.1084 積の積
ユーザー NoneNone
提出日時 2021-03-17 22:44:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 229 ms / 2,000 ms
コード長 1,052 bytes
コンパイル時間 148 ms
コンパイル使用メモリ 82,384 KB
実行使用メモリ 89,184 KB
最終ジャッジ日時 2024-04-27 14:40:30
合計ジャッジ時間 5,497 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
52,820 KB
testcase_01 AC 39 ms
52,672 KB
testcase_02 AC 38 ms
53,428 KB
testcase_03 AC 38 ms
52,824 KB
testcase_04 AC 221 ms
88,004 KB
testcase_05 AC 54 ms
76,992 KB
testcase_06 AC 218 ms
88,640 KB
testcase_07 AC 39 ms
53,944 KB
testcase_08 AC 39 ms
52,760 KB
testcase_09 AC 60 ms
81,036 KB
testcase_10 AC 38 ms
53,212 KB
testcase_11 AC 57 ms
64,496 KB
testcase_12 AC 118 ms
74,328 KB
testcase_13 AC 193 ms
85,584 KB
testcase_14 AC 103 ms
70,776 KB
testcase_15 AC 99 ms
70,096 KB
testcase_16 AC 211 ms
86,996 KB
testcase_17 AC 112 ms
74,292 KB
testcase_18 AC 157 ms
80,836 KB
testcase_19 AC 194 ms
84,884 KB
testcase_20 AC 84 ms
68,196 KB
testcase_21 AC 104 ms
71,768 KB
testcase_22 AC 91 ms
70,196 KB
testcase_23 AC 136 ms
76,428 KB
testcase_24 AC 129 ms
75,492 KB
testcase_25 AC 190 ms
84,456 KB
testcase_26 AC 229 ms
88,644 KB
testcase_27 AC 227 ms
88,612 KB
testcase_28 AC 227 ms
88,660 KB
testcase_29 AC 227 ms
88,932 KB
testcase_30 AC 228 ms
88,684 KB
testcase_31 AC 229 ms
89,184 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def syakutori(A):

    total=1

    def merge(total,Ai):
        total*=Ai
        return total

    def inv_merge(total,Ai):
        total//=Ai
        return total

    def is_possible_merge(total,Ai):
        return total*Ai<10**9

    N=len(A)
    left, right, right_max=0,0,N
    res=1
    T=1
    S=1
    for left in range(right_max):
        while right<right_max and is_possible_merge(total,A[right]):
            total = merge(total,A[right])
            S*=A[right]
            S%=MOD
            T*=S
            T%=MOD
            right+=1
        res*=T
        res%=MOD
        if right==left:
            right+=1
        else:
            total = inv_merge(total,A[left])
            S*=pow(A[left],MOD-2,MOD)
            S%=MOD
            T*=pow(A[left],MOD-1-(right-left),MOD)
            T%=MOD


    return res


#########################################
import sys
input = sys.stdin.readline

K=10**9

MOD=10**9+7

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

if 0 in A:
    print(0)
else:
    res=syakutori(A)
    print(res)
0