結果
| 問題 |
No.1105 Many Triplets
|
| コンテスト | |
| ユーザー |
vwxyz
|
| 提出日時 | 2024-09-28 05:45:59 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 35 ms / 2,000 ms |
| コード長 | 2,443 bytes |
| コンパイル時間 | 104 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 11,136 KB |
| 最終ジャッジ日時 | 2024-09-28 05:46:01 |
| 合計ジャッジ時間 | 2,290 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 |
ソースコード
def Berlekamp_Massey(A,mod):
n = len(A)
B, C = [1], [1]
l, m, p = 0, 1, 1
for i in range(n):
d = A[i]
for j in range(1, l + 1):
d += C[j] * A[i - j]
d %= mod
if d == 0:
m += 1
continue
T = C.copy()
q = pow(p, mod - 2, mod) * d % mod
if len(C) < len(B) + m:
C += [0] * (len(B) + m - len(C))
for j, b in enumerate(B):
C[j + m] -= q * b
C[j + m] %= mod
if 2 * l <= i:
B = T
l, m, p = i + 1 - l, 1, d
else:
m += 1
res = [-c % mod for c in C[1:]]
return res
def BMBM(A,N,mod):
deno=[1]+[-c for c in Berlekamp_Massey(A,mod)]
nume=[0]*(len(deno)-1)
for i in range(len(A)):
for j in range(len(deno)):
if i+j<len(nume):
nume[i+j]+=A[i]*deno[j]
nume[i+j]%=mod
return Bostan_Mori(nume,deno,N,mod=mod)
def Bostan_Mori(poly_nume,poly_deno,N,mod=0,convolve=None):
#if type(poly_nume)==Polynomial:
# poly_nume=poly_nume.polynomial
#if type(poly_deno)==Polynomial:
# poly_deno=poly_deno.polynomial
if convolve==None:
def convolve(poly_nume,poly_deno):
conv=[0]*(len(poly_nume)+len(poly_deno)-1)
for i in range(len(poly_nume)):
for j in range(len(poly_deno)):
x=poly_nume[i]*poly_deno[j]
if mod:
x%=mod
conv[i+j]+=x
if mod:
for i in range(len(conv)):
conv[i]%=mod
return conv
while N:
poly_deno_=[-x if i%2 else x for i,x in enumerate(poly_deno)]
if N%2:
poly_nume=convolve(poly_nume,poly_deno_)[1::2]
else:
poly_nume=convolve(poly_nume,poly_deno_)[::2]
poly_deno=convolve(poly_deno,poly_deno_)[::2]
if mod:
for i in range(len(poly_nume)):
poly_nume[i]%=mod
for i in range(len(poly_deno)):
poly_deno[i]%=mod
N//=2
return poly_nume[0] if poly_nume else 0
N=int(input())
a,b,c=map(int,input().split())
mod=10**9+7
A,B,C=[a],[b],[c]
for i in range(1,9):
a,b,c=a-b,b-c,c-a
a%=mod
b%=mod
c%=mod
A.append(a)
B.append(b)
C.append(c)
N-=1
a=BMBM(A,N,mod)
b=BMBM(B,N,mod)
c=BMBM(C,N,mod)
print(a,b,c)
vwxyz