結果
| 問題 |
No.1879 How many matchings?
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 20:47:27 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 844 bytes |
| コンパイル時間 | 147 ms |
| コンパイル使用メモリ | 82,148 KB |
| 実行使用メモリ | 53,860 KB |
| 最終ジャッジ日時 | 2025-06-12 20:49:02 |
| 合計ジャッジ時間 | 1,321 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 7 WA * 8 |
ソースコード
MOD = 10**9 + 7
def matrix_mult(a, b):
return [
[(a[0][0]*b[0][0] + a[0][1]*b[1][0]) % MOD,
(a[0][0]*b[0][1] + a[0][1]*b[1][1]) % MOD],
[(a[1][0]*b[0][0] + a[1][1]*b[1][0]) % MOD,
(a[1][0]*b[0][1] + a[1][1]*b[1][1]) % MOD]
]
def matrix_pow(mat, power):
result = [[1, 0], [0, 1]] # Identity matrix
while power > 0:
if power % 2 == 1:
result = matrix_mult(result, mat)
mat = matrix_mult(mat, mat)
power //= 2
return result
def fibonacci(n):
if n == 0:
return 0
if n == 1:
return 1
mat = [[1, 1], [1, 0]]
result = matrix_pow(mat, n-1)
return result[0][0]
n = int(input())
if n == 0:
print(0)
else:
if n % 2 == 0:
k = (n // 2) + 1
else:
k = ((n + 1) // 2) + 1
print(fibonacci(k) % MOD)
gew1fw