結果

問題 No.1879 How many matchings?
ユーザー ああいいああいい
提出日時 2022-03-18 22:50:01
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 778 bytes
コンパイル時間 323 ms
コンパイル使用メモリ 82,368 KB
実行使用メモリ 54,456 KB
最終ジャッジ日時 2024-04-14 10:56:24
合計ジャッジ時間 1,836 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,280 KB
testcase_01 AC 36 ms
52,476 KB
testcase_02 AC 36 ms
53,008 KB
testcase_03 AC 36 ms
53,100 KB
testcase_04 WA -
testcase_05 AC 37 ms
53,152 KB
testcase_06 WA -
testcase_07 AC 38 ms
52,524 KB
testcase_08 WA -
testcase_09 AC 39 ms
54,456 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 37 ms
52,904 KB
testcase_14 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
P = 10 ** 9 + 7

def seki(x,y):
    m = len(x)
    l = [[0] * m for _ in range(m)]
    for i in range(m):
        for j in range(m):
            for k in range(m):
                l[i][j] = (l[i][j] + x[i][k] * y[k][j]) % P
    return l

import sys
if n == 1:
    print(1)
    exit()
elif n == 2:
    print(1)
    exit()
elif n == 3:
    print(3)
    exit()
elif n == 4:
    print(2)
    exit()
elif n == 5:
    print(6)
    exit()
    
e = [[0] * 2 for _ in range(2)]
for i in range(2):
    e[i][i] = 1
R = [[1,1,],[1,0]]

if n % 2 == 0:
    u = n//2 - 2
else:
    u = n // 2 - 2
while u:
    if u & 1:
        e = seki(e,R)
    u >>= 1
    R = seki(R,R)

if n % 2 == 0:
    ans = e[0][0] * 2 + e[0][1]
else:
    ans = e[0][0] * 5 + e[0][1] * 2
print(ans % P)
0