結果

問題 No.1510 Simple Integral
ユーザー NoneNone
提出日時 2021-05-14 22:51:51
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,285 bytes
コンパイル時間 172 ms
コンパイル使用メモリ 82,324 KB
実行使用メモリ 63,384 KB
最終ジャッジ日時 2024-04-10 01:59:54
合計ジャッジ時間 3,687 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#####################################################################################################
##### ラグランジュ補間
#####################################################################################################
"""

計算量:
    O(N^2)

参考:
    https://ferin-tech.hatenablog.com/entry/2019/08/11/%E3%83%A9%E3%82%B0%E3%83%A9%E3%83%B3%E3%82%B8%E3%83%A5%E8%A3%9C%E9%96%93

ベンチマーク:
    F - Polynomial Construction: https://atcoder.jp/contests/abc137/submissions/22574915

"""

def convolution(F,a):
    """
    return: f(x)*(x-a)
    """
    _N=len(F)
    res=[0]+F[:]
    for i in range(_N)[::-1]:
        res[i]+=F[i]*(-a)
        res[i]%=MOD
    return res

def division(F,a):
    """
    return: f(x)/(x-a)の 商, 余り
    """
    res=[0]*len(F)
    res[-1]=F[-1]
    for i in range(len(F)-1)[::-1]:
        res[i]=(F[i]+a*res[i+1])
        res[i]%=MOD
    return res[1:], res[0]

def evaluation(F,a):
    """
    :return: F(a)
    """
    q,r=division(F,a)
    return r

def FindFunction(A,B):
    def gcd_ext(a0,b0):
        a,b=abs(a0),abs(b0)
        sign_a,sing_b=(a0>0)-(a0<0),(b0>0)-(b0<0)
        x0,y0,x,y=0,1,1,0
        while b!=0:
            q=a//b
            a,b=b,a%b
            x0,y0,x,y=x-q*x0,y-q*y0,x0,y0
        return (x*sign_a,y*sing_b)

    def mod_inv(a,MOD):
        """
        gcd(a,MOD)=1 を満たす必要あり
        """
        x,y=gcd_ext(a,MOD)
        return x%MOD

    _N=len(A)
    F=[1]
    for a in A:
        F=convolution(F,a)
    Fs=[]
    for a in A:
        q,r=division(F,a)
        Fs.append(q)
    C=[]
    for i,b in enumerate(B):
        val=evaluation(Fs[i],A[i])
        C.append(b*mod_inv(val,MOD)%MOD)
    res=[0]*(_N)
    for c,F in zip(C,Fs):
        for i,p in enumerate(F):
            if i>=_N:
                continue
            res[i]+=c*p
            res[i]%=MOD
    return res

#######################################################################



MOD=998244353

N=int(input())
A=list(map(int, input().split()))
f=[1]
for a in A:
    f=convolution(f,a)
    f=convolution(f,-a)

print(f)

C=[]
for a in A:
    q,r=division(f,a)
    C.append(evaluation(q,a))

print(C)

res=0
sign=pow(-1,(N-1)%2)
for c in C:
    res+=pow(c,MOD-2,MOD)*sign
    res%=MOD
print(res*2%MOD)
0