結果
| 問題 |
No.8046 yukicoderの過去問
|
| コンテスト | |
| ユーザー |
Eki1009
|
| 提出日時 | 2020-11-02 12:13:24 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,189 bytes |
| コンパイル時間 | 325 ms |
| コンパイル使用メモリ | 82,436 KB |
| 実行使用メモリ | 72,716 KB |
| 最終ジャッジ日時 | 2024-07-22 06:10:32 |
| 合計ジャッジ時間 | 4,125 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 5 TLE * 1 -- * 3 |
ソースコード
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)
Eki1009