結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,500 KB
testcase_01 AC 38 ms
53,620 KB
testcase_02 AC 37 ms
53,108 KB
testcase_03 AC 37 ms
52,988 KB
testcase_04 WA -
testcase_05 AC 39 ms
52,204 KB
testcase_06 WA -
testcase_07 AC 40 ms
53,092 KB
testcase_08 WA -
testcase_09 AC 45 ms
53,148 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 38 ms
53,080 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 % P)
0