結果

問題 No.856 増える演算
ユーザー vwxyzvwxyz
提出日時 2024-04-08 06:32:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,830 ms / 3,153 ms
コード長 3,767 bytes
コンパイル時間 402 ms
コンパイル使用メモリ 82,388 KB
実行使用メモリ 306,500 KB
最終ジャッジ日時 2024-10-01 04:53:55
合計ジャッジ時間 59,033 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
53,268 KB
testcase_01 AC 80 ms
77,176 KB
testcase_02 AC 39 ms
53,720 KB
testcase_03 AC 41 ms
55,020 KB
testcase_04 AC 41 ms
54,512 KB
testcase_05 AC 40 ms
53,924 KB
testcase_06 AC 41 ms
55,696 KB
testcase_07 AC 42 ms
54,304 KB
testcase_08 AC 41 ms
55,024 KB
testcase_09 AC 40 ms
54,496 KB
testcase_10 AC 41 ms
54,664 KB
testcase_11 AC 40 ms
55,804 KB
testcase_12 AC 42 ms
55,060 KB
testcase_13 AC 81 ms
77,664 KB
testcase_14 AC 80 ms
77,656 KB
testcase_15 AC 82 ms
77,296 KB
testcase_16 AC 84 ms
77,312 KB
testcase_17 AC 82 ms
77,420 KB
testcase_18 AC 79 ms
77,392 KB
testcase_19 AC 87 ms
77,184 KB
testcase_20 AC 87 ms
77,616 KB
testcase_21 AC 87 ms
77,408 KB
testcase_22 AC 83 ms
77,424 KB
testcase_23 AC 54 ms
66,176 KB
testcase_24 AC 55 ms
66,064 KB
testcase_25 AC 53 ms
64,496 KB
testcase_26 AC 41 ms
55,160 KB
testcase_27 AC 40 ms
54,984 KB
testcase_28 AC 53 ms
65,112 KB
testcase_29 AC 54 ms
65,408 KB
testcase_30 AC 53 ms
66,644 KB
testcase_31 AC 58 ms
65,600 KB
testcase_32 AC 59 ms
65,772 KB
testcase_33 AC 103 ms
77,784 KB
testcase_34 AC 116 ms
79,924 KB
testcase_35 AC 108 ms
78,460 KB
testcase_36 AC 118 ms
79,656 KB
testcase_37 AC 115 ms
78,964 KB
testcase_38 AC 88 ms
77,776 KB
testcase_39 AC 91 ms
77,432 KB
testcase_40 AC 95 ms
78,016 KB
testcase_41 AC 96 ms
77,672 KB
testcase_42 AC 111 ms
79,568 KB
testcase_43 AC 97 ms
77,568 KB
testcase_44 AC 82 ms
77,604 KB
testcase_45 AC 94 ms
77,372 KB
testcase_46 AC 98 ms
77,580 KB
testcase_47 AC 94 ms
78,108 KB
testcase_48 AC 104 ms
78,624 KB
testcase_49 AC 104 ms
77,920 KB
testcase_50 AC 111 ms
78,616 KB
testcase_51 AC 111 ms
79,596 KB
testcase_52 AC 114 ms
79,796 KB
testcase_53 AC 1,721 ms
298,176 KB
testcase_54 AC 1,705 ms
297,272 KB
testcase_55 AC 1,700 ms
298,032 KB
testcase_56 AC 1,654 ms
297,128 KB
testcase_57 AC 1,724 ms
298,648 KB
testcase_58 AC 1,714 ms
298,104 KB
testcase_59 AC 1,773 ms
299,364 KB
testcase_60 AC 1,669 ms
297,600 KB
testcase_61 AC 1,747 ms
299,408 KB
testcase_62 AC 1,712 ms
299,264 KB
testcase_63 AC 1,647 ms
306,500 KB
testcase_64 AC 1,748 ms
298,604 KB
testcase_65 AC 1,642 ms
306,488 KB
testcase_66 AC 1,652 ms
297,572 KB
testcase_67 AC 1,668 ms
298,100 KB
testcase_68 AC 1,742 ms
299,276 KB
testcase_69 AC 1,764 ms
298,860 KB
testcase_70 AC 1,830 ms
300,108 KB
testcase_71 AC 1,761 ms
299,348 KB
testcase_72 AC 1,759 ms
298,356 KB
testcase_73 AC 1,799 ms
300,120 KB
testcase_74 AC 1,780 ms
300,128 KB
testcase_75 AC 1,773 ms
300,128 KB
testcase_76 AC 1,775 ms
300,128 KB
testcase_77 AC 1,768 ms
300,252 KB
testcase_78 AC 1,816 ms
300,228 KB
testcase_79 AC 1,827 ms
299,876 KB
testcase_80 AC 1,786 ms
299,884 KB
testcase_81 AC 1,796 ms
299,872 KB
testcase_82 AC 1,727 ms
299,964 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def FFT(polynomial0,polynomial1,digit=10**5,round_to_int=True):
    assert digit==0 or round_to_int
    if len(polynomial0)*len(polynomial1)<=60:
        polynomial=[0]*(len(polynomial0)+len(polynomial1)-1)
        for i in range(len(polynomial0)):
            for j in range(len(polynomial1)):
                polynomial[i+j]+=polynomial0[i]*polynomial1[j]
        return polynomial
    def DFT(polynomial,n,inverse=False):
        if inverse:
            primitive_root=[math.cos(-i*2*math.pi/(1<<n))+math.sin(-i*2*math.pi/(1<<n))*1j for i in range(1<<n)]
        else:
            primitive_root=[math.cos(i*2*math.pi/(1<<n))+math.sin(i*2*math.pi/(1<<n))*1j for i in range(1<<n)]
        if inverse:
            for bit in range(1,n+1):
                a=1<<bit-1
                for i in range(1<<n-bit):
                    for j in range(a):
                        s=i*2*a+j
                        t=s+a
                        polynomial[s],polynomial[t]=polynomial[s]+polynomial[t]*primitive_root[j<<n-bit],polynomial[s]-polynomial[t]*primitive_root[j<<n-bit]
        else:
            for bit in range(n,0,-1):
                a=1<<bit-1
                for i in range(1<<n-bit):
                    for j in range(a):
                        s=i*2*a+j
                        t=s+a
                        polynomial[s],polynomial[t]=polynomial[s]+polynomial[t],primitive_root[j<<n-bit]*(polynomial[s]-polynomial[t])

    def FFT_(polynomial0,polynomial1,round_to_int=True):
        N0=len(polynomial0)
        N1=len(polynomial1)
        N=N0+N1-1
        n=(N-1).bit_length()
        polynomial0=polynomial0+[0]*((1<<n)-N0)
        polynomial1=polynomial1+[0]*((1<<n)-N1)
        DFT(polynomial0,n)
        DFT(polynomial1,n)
        fft=[x*y for x,y in zip(polynomial0,polynomial1)]
        DFT(fft,n,inverse=True)
        if round_to_int:
            fft=[round((fft[i]/(1<<n)).real) for i in range(N)]
        else:
            fft=[(fft[i]/(1<<n)).real for i in range(N)]
        return fft

    if digit:
        N0=len(polynomial0)
        N1=len(polynomial1)
        N=N0+N1-1
        polynomial00,polynomial01=[None]*N0,[None]*N0
        polynomial10,polynomial11=[None]*N1,[None]*N1
        for i in range(N0):
            polynomial00[i],polynomial01[i]=divmod(polynomial0[i],digit)
        for i in range(N1):
            polynomial10[i],polynomial11[i]=divmod(polynomial1[i],digit)
        polynomial=[0]*N
        for i,x in enumerate(FFT_(polynomial00,polynomial10)):
            polynomial[i]+=x*(digit**2-digit)
        for i,x in enumerate(FFT_(polynomial01,polynomial11)):
            polynomial[i]-=x*(digit-1)
        for i,x in enumerate(FFT_([x1+x2 for x1,x2 in zip(polynomial00,polynomial01)],[x1+x2 for x1,x2 in zip(polynomial10,polynomial11)])):
            polynomial[i]+=x*digit
    else:
        polynomial=FFT_(polynomial0,polynomial1,round_to_int=round_to_int)
    return polynomial

import math
import sys
#sys.set_int_max_str_digits(10**7)

N=int(input())
mod=998244353
A=list(map(int,input().split()))
max_A=max(A)
cnt=[0]*(max_A+1)
for a in A:
    cnt[a]+=1
cnt=FFT(cnt,cnt)
mod=10**9+7
M=1
prod_A=1
for a in A:
    prod_A*=a
    prod_A%=mod
for a in A:
    cnt[a*2]-=1
ans=1
for a in range(1,max_A*2+1):
    ans*=pow(a,cnt[a]//2,mod)
    ans%=mod
cumsum=[0]+A
for i in range(1,N+1):
    cumsum[i]+=cumsum[i-1]
for i in range(N):
    ans*=pow(A[i],cumsum[N]-cumsum[i+1],mod)
    ans%=mod
j=A.index(min(A))
if j:
    i=A[:j].index(min(A[:j]))
else:
    i=None
if j<N-1:
    k=j+1+A[j+1:N].index(min(A[j+1:N]))
else:
    k=None
if i==None:
    mi=(A[j]+A[k])*A[j]**A[k]
elif k==None:
    mi=(A[i]+A[j])*A[i]**A[j]
else:
    mi=min((A[j]+A[k])*A[j]**A[k],(A[i]+A[j])*A[i]**A[j])
ans*=pow(mi,mod-2,mod)
ans%=mod
print(ans)
0