結果

問題 No.3046 yukicoderの過去問
ユーザー Eki1009Eki1009
提出日時 2020-11-02 12:13:24
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,189 bytes
コンパイル時間 541 ms
コンパイル使用メモリ 87,060 KB
実行使用メモリ 75,900 KB
最終ジャッジ日時 2023-09-29 11:46:36
合計ジャッジ時間 5,238 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,328 KB
testcase_01 AC 73 ms
71,364 KB
testcase_02 AC 72 ms
71,284 KB
testcase_03 AC 80 ms
75,900 KB
testcase_04 AC 73 ms
71,340 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**7)
mod = 10**9+7

def convolution(A, B):
    la = len(A)
    lb = len(B)
    res = [0]*(la+lb-1)
    for i, a in enumerate(A):
        for j, b in enumerate(B):
            res[i+j] += a*b
            res[i+j] %= mod
    return res

def poly_mod(X, Q):
    a = len(X)
    b = len(Q)
    if a < b:
        return X
    for i in range(a-b, -1, -1):
        d = X[i+b-1]
        for j, q in enumerate(Q):
            X[i+j] -= q*d
            X[i+j] %= mod
    return X[:b-1]

def poly_pow(C, n, Q):
    if n == 1:
        return C
    d = len(C)
    if n%2:
        res = convolution(poly_pow(C, n-1, Q), C)
    else:
        T = poly_pow(C, n//2, Q)
        res = convolution(T, T)
    res = poly_mod(res, Q)
    return res
        
#[x^n]P/Qを求める
def poly_coef(Q, P, n):
    C = [-q for q in Q[1:]]
    inv = pow(Q[-1], mod-2, mod)
    norm_Q = [q*inv%mod for q in Q]
    X = poly_pow(C, n, norm_Q)
    res = convolution(X, P)
    res = poly_mod(res, norm_Q)
    return res[0]

k = int(input())
n = int(input())
A = tuple(map(int, input().split()))
Q = [0]*(A[-1]+1)
Q[0] = 1
for a in A:
    Q[a] = -1
P = [1]
ans = poly_coef(Q, P, k)
print(ans)
0