結果
問題 | No.194 フィボナッチ数列の理解(1) |
ユーザー | mkawa2 |
提出日時 | 2021-09-23 00:16:13 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 490 ms / 5,000 ms |
コード長 | 1,702 bytes |
コンパイル時間 | 81 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 57,856 KB |
最終ジャッジ日時 | 2024-07-05 09:21:45 |
合計ジャッジ時間 | 8,748 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 32 ms
11,008 KB |
testcase_01 | AC | 30 ms
10,880 KB |
testcase_02 | AC | 370 ms
11,008 KB |
testcase_03 | AC | 60 ms
10,880 KB |
testcase_04 | AC | 153 ms
11,008 KB |
testcase_05 | AC | 133 ms
10,752 KB |
testcase_06 | AC | 157 ms
10,880 KB |
testcase_07 | AC | 239 ms
10,880 KB |
testcase_08 | AC | 52 ms
10,880 KB |
testcase_09 | AC | 191 ms
10,880 KB |
testcase_10 | AC | 91 ms
10,880 KB |
testcase_11 | AC | 88 ms
10,880 KB |
testcase_12 | AC | 125 ms
11,008 KB |
testcase_13 | AC | 65 ms
11,008 KB |
testcase_14 | AC | 36 ms
10,880 KB |
testcase_15 | AC | 255 ms
10,880 KB |
testcase_16 | AC | 220 ms
10,880 KB |
testcase_17 | AC | 81 ms
10,880 KB |
testcase_18 | AC | 238 ms
11,008 KB |
testcase_19 | AC | 324 ms
10,880 KB |
testcase_20 | AC | 274 ms
26,496 KB |
testcase_21 | AC | 490 ms
57,588 KB |
testcase_22 | AC | 451 ms
57,856 KB |
testcase_23 | AC | 44 ms
12,544 KB |
testcase_24 | AC | 229 ms
33,024 KB |
testcase_25 | AC | 208 ms
31,076 KB |
testcase_26 | AC | 203 ms
30,080 KB |
testcase_27 | AC | 264 ms
36,224 KB |
testcase_28 | AC | 78 ms
16,236 KB |
testcase_29 | AC | 427 ms
54,016 KB |
testcase_30 | AC | 325 ms
10,880 KB |
testcase_31 | AC | 30 ms
10,880 KB |
testcase_32 | AC | 121 ms
11,264 KB |
testcase_33 | AC | 158 ms
10,880 KB |
testcase_34 | AC | 130 ms
10,880 KB |
testcase_35 | AC | 120 ms
11,264 KB |
testcase_36 | AC | 259 ms
10,880 KB |
testcase_37 | AC | 47 ms
10,752 KB |
testcase_38 | AC | 306 ms
10,880 KB |
testcase_39 | AC | 137 ms
10,880 KB |
ソースコード
import sys # sys.setrecursionlimit(200005) int1 = lambda x: int(x)-1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LI1(): return list(map(int1, sys.stdin.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 SI(): return sys.stdin.readline().rstrip() dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] # dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] inf = 10**16 # md = 998244353 md = 10**9+7 def dot(aa, bb): h = len(aa) w = len(bb[0]) res = [[0]*w for _ in range(h)] for i, row in enumerate(aa): for j, col in enumerate(zip(*bb)): v = 0 # for a, b in zip(row, col): v += a*b # res[i][j] = v%md for a, b in zip(row, col): v += a*b%md res[i][j] = v%md return res def matpow(mat, e): n = len(mat) res = [[1 if i == j else 0 for j in range(n)] for i in range(n)] while e: if e & 1: res = dot(res, mat) mat = dot(mat, mat) e >>= 1 return res def solve1(): s = sum(aa)%md for _ in range(k-n): aa.append(s) s = s*2-aa[-n-1] s %= md s = 0 for a in aa[:k]: s += a s %= md print(aa[k-1], s) def solve2(): mat = [[0]*(n-1)+[1]*2 for _ in range(n+1)] for i in range(1, n): mat[i][i-1] = 1 mat[n][n-1] = 0 aa.append(sum(aa)) mat = matpow(mat, k-n) ans = dot([aa], mat) print(ans[0][-2], ans[0][-1]) n, k = LI() aa = LI() if k <= 10**6: solve1() else: solve2()