結果
問題 | No.891 隣接3項間の漸化式 |
ユーザー | mkawa2 |
提出日時 | 2021-03-04 16:05:43 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,272 bytes |
コンパイル時間 | 143 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 11,008 KB |
最終ジャッジ日時 | 2024-10-05 00:25:15 |
合計ジャッジ時間 | 2,275 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 26 ms
10,880 KB |
testcase_01 | AC | 27 ms
10,752 KB |
testcase_02 | AC | 28 ms
10,880 KB |
testcase_03 | AC | 26 ms
10,880 KB |
testcase_04 | AC | 26 ms
10,880 KB |
testcase_05 | AC | 26 ms
10,624 KB |
testcase_06 | AC | 26 ms
10,880 KB |
testcase_07 | AC | 26 ms
10,752 KB |
testcase_08 | AC | 25 ms
11,008 KB |
testcase_09 | AC | 25 ms
10,880 KB |
testcase_10 | AC | 25 ms
10,880 KB |
testcase_11 | AC | 25 ms
10,880 KB |
testcase_12 | AC | 25 ms
10,880 KB |
testcase_13 | RE | - |
testcase_14 | AC | 26 ms
10,752 KB |
testcase_15 | AC | 25 ms
10,624 KB |
testcase_16 | AC | 25 ms
10,624 KB |
testcase_17 | AC | 26 ms
10,880 KB |
testcase_18 | AC | 26 ms
10,880 KB |
testcase_19 | AC | 26 ms
10,752 KB |
testcase_20 | WA | - |
testcase_21 | AC | 25 ms
10,880 KB |
testcase_22 | AC | 25 ms
10,880 KB |
testcase_23 | AC | 26 ms
11,008 KB |
testcase_24 | AC | 25 ms
10,752 KB |
testcase_25 | AC | 26 ms
10,752 KB |
testcase_26 | AC | 25 ms
10,880 KB |
testcase_27 | AC | 26 ms
10,880 KB |
testcase_28 | AC | 26 ms
11,008 KB |
testcase_29 | AC | 25 ms
10,880 KB |
testcase_30 | AC | 25 ms
10,752 KB |
testcase_31 | AC | 26 ms
10,624 KB |
testcase_32 | AC | 25 ms
10,880 KB |
testcase_33 | AC | 25 ms
10,880 KB |
testcase_34 | AC | 26 ms
10,880 KB |
testcase_35 | AC | 25 ms
10,752 KB |
testcase_36 | AC | 26 ms
10,752 KB |
testcase_37 | AC | 26 ms
10,752 KB |
testcase_38 | AC | 27 ms
10,752 KB |
testcase_39 | AC | 26 ms
10,752 KB |
testcase_40 | AC | 26 ms
10,752 KB |
testcase_41 | AC | 26 ms
11,008 KB |
ソースコード
import sys sys.setrecursionlimit(10**6) int1 = lambda x: int(x)-1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.buffer.readline()) def FI(): return float(sys.stdin.buffer.readline()) def MI(): return map(int, sys.stdin.buffer.readline().split()) def MF(): return map(float, sys.stdin.buffer.readline().split()) def MI1(): return map(int1, sys.stdin.buffer.readline().split()) def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def LI1(): return list(map(int1, sys.stdin.buffer.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def BI(): return sys.stdin.buffer.readline().rstrip() def SI(): return sys.stdin.buffer.readline().rstrip().decode() dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] inf = 10**16 # md = 998244353 md = 10**9+7 # af(n)+bf(n+1)+cf(n+2)+df(n+3)=f(n+4)みたいなとき # coeff=[a,b,c,d] # 初期値f0(f(0)からf(3)) class Fibonacci: def __init__(self, coeff, f0): self.f0 = f0 n = len(coeff) ff = [[0]*n for _ in range(2*n-1)] for i in range(n): ff[i][i] = 1 for i in range(n, 2*n-1): ffi = ff[i] for j, c in enumerate(coeff, i-n): ffj = ff[j] for k in range(n): ffi[k] += c*ffj[k] self.bn = 1 << (n-1).bit_length() self.base = ff[self.bn] self.ff = ff self.n = n def __mm(self, aa, bb): n = self.n res = [0]*(n*2-1) for i, a in enumerate(aa): for j, b in enumerate(bb): res[i+j] += a*b res[i+j] %= md for i in range(n, 2*n-1): c = res[i] ffi = self.ff[i] for j in range(n): res[j] += c*ffi[j] res[j] %= md return res[:n] def v(self, x): base = self.base aa = self.ff[x%self.bn] x //= self.bn while x: if x & 1: aa = self.__mm(aa, base) base = self.__mm(base, base) x >>= 1 return sum(a*f%md for a, f in zip(aa, self.f0))%md a, b, n = MI() if b == 0: print(pow(a, n-1, md)) else: fibo = Fibonacci([b, a], [0, 1]) print(fibo.v(n))