結果

問題 No.1491 銀将
ユーザー convexineqconvexineq
提出日時 2021-05-01 03:15:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 81 ms / 1,000 ms
コード長 706 bytes
コンパイル時間 276 ms
コンパイル使用メモリ 87,048 KB
実行使用メモリ 76,144 KB
最終ジャッジ日時 2023-09-26 12:10:42
合計ジャッジ時間 3,541 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
70,936 KB
testcase_01 AC 72 ms
70,944 KB
testcase_02 AC 76 ms
75,984 KB
testcase_03 AC 78 ms
76,072 KB
testcase_04 AC 79 ms
76,028 KB
testcase_05 AC 77 ms
76,076 KB
testcase_06 AC 75 ms
75,908 KB
testcase_07 AC 75 ms
76,116 KB
testcase_08 AC 77 ms
75,984 KB
testcase_09 AC 72 ms
71,184 KB
testcase_10 AC 72 ms
71,068 KB
testcase_11 AC 77 ms
71,068 KB
testcase_12 AC 76 ms
71,304 KB
testcase_13 AC 74 ms
70,796 KB
testcase_14 AC 79 ms
75,884 KB
testcase_15 AC 80 ms
76,124 KB
testcase_16 AC 81 ms
76,144 KB
testcase_17 AC 81 ms
75,928 KB
testcase_18 AC 78 ms
76,028 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def polymul(f,g):
    lf = len(f)
    lg = len(g)
    res = [0]*(lf+lg-1)
    for i in range(lf):
        for j in range(lg):
            res[i+j] += f[i]*g[j]
            res[i+j] %= MOD
    return res

"""
[x^N]f/g を O(K^2 log N) で求めるMori法 (K = deg(g))
f,g は多項式
polymul を convolution に変えれば O(K log(K) log N)
"""
def fps_nth_term(f,g,N):
    assert g[0] != 0
    while N:
        h = g[:]
        for i in range(1,len(g),2):
            h[i] = -h[i]
        f = polymul(f,h)[N%2:N+1:2]
        g = polymul(g,h)[:N+1:2]
        N //= 2
    return f[0]*pow(g[0],MOD-2,MOD)%MOD

k = int(input())

MOD = 10**22+9
ans = fps_nth_term([1, 3, 3, 1], [1, -3, 3, -1, 0],k)
print(ans)
0