結果
| 問題 |
No.1879 How many matchings?
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-04-16 01:07:23 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,012 bytes |
| コンパイル時間 | 473 ms |
| コンパイル使用メモリ | 82,200 KB |
| 実行使用メモリ | 54,008 KB |
| 最終ジャッジ日時 | 2025-04-16 01:08:52 |
| 合計ジャッジ時間 | 1,565 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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(matrix, power):
result = [[1, 0], [0, 1]] # Identity matrix
while power > 0:
if power % 2 == 1:
result = matrix_mult(result, matrix)
matrix = matrix_mult(matrix, matrix)
power //= 2
return result
def fib(n):
if n == 0:
return 0
# F(n) using matrix exponentiation
matrix = [[1, 1], [1, 0]]
powered = matrix_pow(matrix, n-1)
return powered[0][0]
n = int(input())
if n % 2 == 0:
k = n // 2
print(fib(k + 1) % MOD)
else:
k = (n - 1) // 2
# For odd n, the pattern is different. This part is a placeholder and may need adjustment.
# The code here is a guess based on even cases and may not work for all odd n.
print(fib(k + 2) % MOD)
lam6er