結果
問題 |
No.613 Solitude by the window
|
ユーザー |
|
提出日時 | 2017-12-12 23:30:13 |
言語 | Python2 (2.7.18) |
結果 |
WA
|
実行時間 | - |
コード長 | 831 bytes |
コンパイル時間 | 279 ms |
コンパイル使用メモリ | 6,912 KB |
実行使用メモリ | 6,272 KB |
最終ジャッジ日時 | 2024-12-14 06:41:05 |
合計ジャッジ時間 | 1,269 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 14 WA * 7 |
ソースコード
#!/usr/bin/python2 # -*- coding: utf-8 -*- # † n, mod = map(int, raw_input().split()) p = pow(2, n, mod-1) + mod - 1 def matmul(A, B): p, q = len(A[0]), len(B) if p != q: raise ValueError('len(A[0])={} len(B)={}'.format(p, q)) rows, cols, times = len(A), len(B[0]), len(A[0]) res = [[0] * cols for _ in xrange(rows)] for r in xrange(rows): for c in xrange(cols): res[r][c] = sum(A[r][i]*B[i][c] % mod for i in xrange(times)) % mod return res def matpow(A, n): m = len(A) res = [[int(i==j) for j in xrange(m)] for i in xrange(m)] while n > 0: if n & 1: res = matmul(res, A) A = matmul(A, A) n >>= 1 return res A = [[2, 3], [1, 2]] B = matpow(A, p) C = [[1], [0]] D = matmul(B, C) res = 2 * D[0][0] - 2 res %= mod print res