結果

問題 No.1879 How many matchings?
ユーザー horitaka1999horitaka1999
提出日時 2022-03-18 23:55:17
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 734 bytes
コンパイル時間 200 ms
コンパイル使用メモリ 82,420 KB
実行使用メモリ 53,768 KB
最終ジャッジ日時 2024-04-14 12:35:14
合計ジャッジ時間 1,674 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 41 ms
52,224 KB
testcase_02 WA -
testcase_03 AC 40 ms
52,608 KB
testcase_04 WA -
testcase_05 AC 37 ms
53,116 KB
testcase_06 WA -
testcase_07 AC 38 ms
53,768 KB
testcase_08 WA -
testcase_09 AC 39 ms
53,408 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 45 ms
53,612 KB
testcase_14 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

def dot(aa, bb):
    h = len(aa)
    w = len(bb[0])
    res = [[0]*w for _ in range(h)]
    for i, row in enumerate(aa):
        for j, col in enumerate(zip(*bb)):
            v = 0
            # for a, b in zip(row, col): v += a*b
            # res[i][j] = v%md
            for a, b in zip(row, col): v += a*b%md
            res[i][j] = v%md
    return res

def matpow(mat, e):
    n = len(mat)
    res = [[1 if i == j else 0 for j in range(n)] for i in range(n)]
    while e:
        if e & 1: res = dot(res, mat)
        mat = dot(mat, mat)
        e >>= 1
    return res
md = 10 ** 9 + 7
N = int(input())
A = [[0,1],
     [1,1]]
if N % 2 == 0:
    powA = matpow(A,N//2)
    B = [[1],[1]]
    ans = dot(powA,B)
    print(ans[0][0])
0