結果

問題 No.906 Y字グラフ
ユーザー vwxyzvwxyz
提出日時 2024-04-15 05:35:11
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 2,410 bytes
コンパイル時間 92 ms
コンパイル使用メモリ 13,056 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-04-15 05:35:14
合計ジャッジ時間 2,150 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
11,008 KB
testcase_01 AC 34 ms
11,008 KB
testcase_02 AC 32 ms
11,008 KB
testcase_03 AC 32 ms
10,880 KB
testcase_04 AC 31 ms
11,008 KB
testcase_05 AC 32 ms
11,136 KB
testcase_06 AC 32 ms
11,008 KB
testcase_07 AC 31 ms
11,008 KB
testcase_08 AC 33 ms
11,008 KB
testcase_09 AC 31 ms
11,008 KB
testcase_10 AC 31 ms
11,008 KB
testcase_11 AC 31 ms
11,008 KB
testcase_12 AC 31 ms
11,136 KB
testcase_13 AC 33 ms
11,008 KB
testcase_14 AC 32 ms
11,008 KB
testcase_15 AC 32 ms
11,008 KB
testcase_16 AC 32 ms
11,008 KB
testcase_17 AC 33 ms
11,008 KB
testcase_18 AC 32 ms
11,008 KB
testcase_19 AC 33 ms
11,008 KB
testcase_20 AC 33 ms
11,008 KB
testcase_21 AC 33 ms
11,008 KB
testcase_22 AC 32 ms
11,008 KB
testcase_23 AC 34 ms
11,008 KB
testcase_24 AC 33 ms
11,008 KB
testcase_25 AC 32 ms
11,008 KB
testcase_26 AC 34 ms
11,008 KB
testcase_27 AC 34 ms
11,008 KB
testcase_28 AC 38 ms
11,008 KB
testcase_29 AC 33 ms
11,008 KB
testcase_30 AC 32 ms
10,880 KB
testcase_31 AC 33 ms
11,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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]

def Berlekamp_Massey(A):
    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=0):
    deno=[1]+[-c for c in Berlekamp_Massey(A)]
    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)

N=int(input())-4
cnt=[]
for i in range(4,16):
    c=0
    for x in range(1,i):
        for y in range(x,i):
            for z in range(y,i):
                if x+y+z==i-1:
                    c+=1
    cnt.append(c)
mod=10**9+7
ans=BMBM(cnt,N,mod)
print(ans)
0