結果

問題 No.1084 積の積
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2022-04-01 11:27:25
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 570 ms / 2,000 ms
コード長 1,446 bytes
コンパイル時間 93 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 21,708 KB
最終ジャッジ日時 2024-04-29 18:49:26
合計ジャッジ時間 9,682 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,752 KB
testcase_01 AC 28 ms
10,752 KB
testcase_02 AC 28 ms
10,624 KB
testcase_03 AC 30 ms
10,752 KB
testcase_04 AC 166 ms
12,624 KB
testcase_05 AC 50 ms
12,748 KB
testcase_06 AC 143 ms
12,624 KB
testcase_07 AC 27 ms
10,880 KB
testcase_08 AC 27 ms
10,752 KB
testcase_09 AC 302 ms
20,728 KB
testcase_10 AC 29 ms
10,752 KB
testcase_11 AC 45 ms
11,136 KB
testcase_12 AC 249 ms
15,292 KB
testcase_13 AC 467 ms
20,164 KB
testcase_14 AC 186 ms
14,088 KB
testcase_15 AC 178 ms
13,780 KB
testcase_16 AC 532 ms
21,708 KB
testcase_17 AC 221 ms
14,932 KB
testcase_18 AC 355 ms
17,712 KB
testcase_19 AC 476 ms
20,240 KB
testcase_20 AC 125 ms
13,000 KB
testcase_21 AC 191 ms
14,136 KB
testcase_22 AC 149 ms
13,296 KB
testcase_23 AC 288 ms
16,512 KB
testcase_24 AC 273 ms
15,844 KB
testcase_25 AC 472 ms
20,328 KB
testcase_26 AC 556 ms
19,612 KB
testcase_27 AC 551 ms
19,604 KB
testcase_28 AC 556 ms
19,736 KB
testcase_29 AC 553 ms
19,612 KB
testcase_30 AC 570 ms
19,608 KB
testcase_31 AC 557 ms
19,612 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
mod=10**9+7
th=10**9
class MyQue:
    """
    value:10**9未満判定、pop時のvalue_pyrの計算に使用
    value_pyr:積の積の計算に使用。
    """
    def __init__(self):
        self.q=deque()
        self.value=1
        self.value_pyr=1
        self.length=0
    def push(self,x):
        self.value*=x
        self.q.append(x)
        #assert self.value<th
        self.length+=1
        self.value_pyr*=pow(x,self.length,mod)
        if self.value_pyr>=mod:self.value_pyr%=mod    
    def pop(self):
        #assert self.length>0,(self.value,q,self.length)
        self.value_pyr*=pow(self.value,mod-2,mod)
        if self.value_pyr>=mod:self.value_pyr%=mod
        x=self.q.popleft()
        self.value//=x
        #assert self.value<th
        self.length-=1
def main0(n,a):
    q=MyQue()
    ans=1
    for i in range(n):
        if a[i]==0:return 0
        while q.value*a[i]>=th:
            q.pop()
        q.push(a[i])
        ans*=q.value_pyr
        if ans>=mod:ans%=mod
    return ans

def main1(n,a):
    ans=1
    for i in range(n):
        for j in range(i,n):
            x=1
            for k in range(i,j+1):
                x*=a[k]
            if x<th:
                ans*=x
                ans%=mod
    return ans
    
if __name__=='__main__':
    n=int(input())
    a=list(map(int,input().split()))
    ans0=main0(n,a)
    print(ans0)
    
    #ans1=main1(n,a)
    #print(ans1)
0