結果
問題 | No.1879 How many matchings? |
ユーザー | 👑 tamato |
提出日時 | 2022-03-18 22:24:02 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 48 ms / 2,000 ms |
コード長 | 917 bytes |
コンパイル時間 | 431 ms |
コンパイル使用メモリ | 82,164 KB |
実行使用メモリ | 63,252 KB |
最終ジャッジ日時 | 2024-04-14 10:16:37 |
合計ジャッジ時間 | 1,883 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
52,348 KB |
testcase_01 | AC | 37 ms
53,304 KB |
testcase_02 | AC | 38 ms
53,140 KB |
testcase_03 | AC | 39 ms
54,496 KB |
testcase_04 | AC | 38 ms
53,260 KB |
testcase_05 | AC | 39 ms
53,472 KB |
testcase_06 | AC | 42 ms
52,860 KB |
testcase_07 | AC | 39 ms
52,648 KB |
testcase_08 | AC | 38 ms
53,140 KB |
testcase_09 | AC | 47 ms
62,164 KB |
testcase_10 | AC | 47 ms
61,848 KB |
testcase_11 | AC | 48 ms
62,904 KB |
testcase_12 | AC | 48 ms
63,252 KB |
testcase_13 | AC | 48 ms
62,596 KB |
testcase_14 | AC | 48 ms
63,124 KB |
ソースコード
mod = 1000000007 def main(): import sys input = sys.stdin.readline def matmul(A, B): C = [[0] * len(B[0]) for _ in range(len(A))] for i in range(len(A)): for k in range(len(B)): for j in range(len(B[0])): C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % mod return C def matpow(A, p): n = len(A) B = [[0] * n for _ in range(n)] for i in range(n): B[i][i] = 1 while p > 0: if p & 1: B = matmul(B, A) A = matmul(A, A) p >>= 1 return B N = int(input()) vec = [[1], [0], [0], [0]] mat = [[1, 0, 1, 0], [1, 1, 1, 1], [1, 0, 0, 0], [0, 1, 0, 0]] NN = (N + 1) // 2 ans = matmul(matpow(mat, NN), vec) if N & 1: print(ans[1][0]) else: print(ans[0][0]) if __name__ == '__main__': main()