結果

問題 No.1879 How many matchings?
ユーザー ああいいああいい
提出日時 2022-03-18 21:43:34
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 971 bytes
コンパイル時間 427 ms
コンパイル使用メモリ 82,028 KB
実行使用メモリ 63,428 KB
最終ジャッジ日時 2024-04-14 09:28:35
合計ジャッジ時間 2,245 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
53,316 KB
testcase_01 AC 47 ms
53,084 KB
testcase_02 AC 48 ms
53,424 KB
testcase_03 AC 47 ms
53,092 KB
testcase_04 WA -
testcase_05 AC 47 ms
53,696 KB
testcase_06 WA -
testcase_07 AC 48 ms
52,728 KB
testcase_08 WA -
testcase_09 AC 51 ms
53,576 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 50 ms
53,220 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()

if n % 2 == 0:
    m = 2
    R = [[1,1,],[1,0]]
else:
    m = 4
    R = [[1,1,1,1,],[1,0,0,0,],[0,1,0,0,],[0,0,1,0]]
e = [[0] * m for _ in range(m)]
for i in range(m):
    e[i][i] = 1
if n % 2 == 0:
    u = n // 2 - 2
    while u:
        if u & 1:
            e = seki(e,R)
        u >>= 1
        R = seki(R,R)
    ans = e[0][0] * 2 + e[0][1] * 1
    print(ans % P)
else:
    u = n - 4
    while u:
        if u & 1:
            e = seki(e,R)
        u >>= 1
        R = seki(R,R)
    ans = e[0][0] * 2 + e[0][1] * 3 + e[0][2] * 1 * e[0][3]
    print(ans)
0