結果

問題 No.1084 積の積
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2022-04-01 11:18:44
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 975 bytes
コンパイル時間 118 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 21,540 KB
最終ジャッジ日時 2024-04-29 18:39:56
合計ジャッジ時間 11,232 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
10,752 KB
testcase_01 AC 28 ms
10,624 KB
testcase_02 AC 27 ms
10,752 KB
testcase_03 AC 28 ms
10,624 KB
testcase_04 AC 199 ms
12,492 KB
testcase_05 WA -
testcase_06 AC 172 ms
12,620 KB
testcase_07 WA -
testcase_08 AC 29 ms
10,752 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 48 ms
11,136 KB
testcase_12 AC 255 ms
15,184 KB
testcase_13 AC 513 ms
20,000 KB
testcase_14 AC 203 ms
14,044 KB
testcase_15 AC 188 ms
13,872 KB
testcase_16 AC 569 ms
21,540 KB
testcase_17 AC 234 ms
14,632 KB
testcase_18 AC 388 ms
17,772 KB
testcase_19 AC 511 ms
20,344 KB
testcase_20 AC 135 ms
12,800 KB
testcase_21 AC 208 ms
13,976 KB
testcase_22 AC 160 ms
13,172 KB
testcase_23 AC 315 ms
16,368 KB
testcase_24 AC 290 ms
15,868 KB
testcase_25 AC 533 ms
20,292 KB
testcase_26 AC 599 ms
19,556 KB
testcase_27 AC 600 ms
19,424 KB
testcase_28 AC 606 ms
19,680 KB
testcase_29 AC 604 ms
19,688 KB
testcase_30 AC 590 ms
19,552 KB
testcase_31 AC 598 ms
19,552 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
    
n=int(input())
a=list(map(int,input().split()))

q=MyQue()
ans=1
for i in range(n):
  if a[i]==0:
    del q
    q=MyQue()
    continue
  while q.value*a[i]>=th:
    q.pop()
  q.push(a[i])
  ans*=q.value_pyr
  if ans>=mod:ans%=mod
print(ans)
0