結果

問題 No.1084 積の積
ユーザー NoneNone
提出日時 2021-03-17 23:03:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 129 ms / 2,000 ms
コード長 947 bytes
コンパイル時間 165 ms
コンパイル使用メモリ 82,288 KB
実行使用メモリ 86,748 KB
最終ジャッジ日時 2024-04-27 14:57:14
合計ジャッジ時間 3,867 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
52,592 KB
testcase_01 AC 39 ms
53,224 KB
testcase_02 AC 33 ms
53,692 KB
testcase_03 AC 36 ms
52,248 KB
testcase_04 AC 128 ms
86,348 KB
testcase_05 AC 51 ms
76,956 KB
testcase_06 AC 129 ms
86,748 KB
testcase_07 AC 36 ms
52,960 KB
testcase_08 AC 34 ms
53,940 KB
testcase_09 AC 54 ms
82,420 KB
testcase_10 AC 33 ms
52,720 KB
testcase_11 AC 47 ms
63,744 KB
testcase_12 AC 76 ms
71,376 KB
testcase_13 AC 113 ms
83,072 KB
testcase_14 AC 71 ms
69,200 KB
testcase_15 AC 67 ms
70,076 KB
testcase_16 AC 119 ms
85,380 KB
testcase_17 AC 72 ms
70,852 KB
testcase_18 AC 96 ms
78,152 KB
testcase_19 AC 117 ms
82,480 KB
testcase_20 AC 57 ms
66,332 KB
testcase_21 AC 69 ms
68,504 KB
testcase_22 AC 64 ms
67,152 KB
testcase_23 AC 88 ms
74,568 KB
testcase_24 AC 81 ms
73,776 KB
testcase_25 AC 112 ms
82,880 KB
testcase_26 AC 128 ms
85,160 KB
testcase_27 AC 126 ms
85,528 KB
testcase_28 AC 128 ms
84,912 KB
testcase_29 AC 129 ms
85,048 KB
testcase_30 AC 129 ms
85,808 KB
testcase_31 AC 125 ms
85,040 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])
            T*=total
            T%=MOD
            right+=1
        res*=T
        res%=MOD
        if right==left:
            right+=1
        else:
            total = inv_merge(total,A[left])
            T*=pow(A[left],MOD-1-(right-left),MOD)
            T%=MOD


    return res


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

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