結果
問題 | No.194 フィボナッチ数列の理解(1) |
ユーザー | qqqq |
提出日時 | 2019-07-08 17:17:57 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 345 ms / 5,000 ms |
コード長 | 1,418 bytes |
コンパイル時間 | 449 ms |
コンパイル使用メモリ | 82,240 KB |
実行使用メモリ | 78,080 KB |
最終ジャッジ日時 | 2024-10-08 22:29:26 |
合計ジャッジ時間 | 7,848 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
52,096 KB |
testcase_01 | AC | 38 ms
52,608 KB |
testcase_02 | AC | 345 ms
76,544 KB |
testcase_03 | AC | 89 ms
75,920 KB |
testcase_04 | AC | 163 ms
75,776 KB |
testcase_05 | AC | 148 ms
76,160 KB |
testcase_06 | AC | 164 ms
76,032 KB |
testcase_07 | AC | 249 ms
76,032 KB |
testcase_08 | AC | 81 ms
75,648 KB |
testcase_09 | AC | 195 ms
76,288 KB |
testcase_10 | AC | 115 ms
76,288 KB |
testcase_11 | AC | 114 ms
75,908 KB |
testcase_12 | AC | 156 ms
76,176 KB |
testcase_13 | AC | 95 ms
75,904 KB |
testcase_14 | AC | 69 ms
73,984 KB |
testcase_15 | AC | 271 ms
76,160 KB |
testcase_16 | AC | 244 ms
75,776 KB |
testcase_17 | AC | 113 ms
76,288 KB |
testcase_18 | AC | 250 ms
75,904 KB |
testcase_19 | AC | 325 ms
76,416 KB |
testcase_20 | AC | 58 ms
73,984 KB |
testcase_21 | AC | 64 ms
78,080 KB |
testcase_22 | AC | 61 ms
74,112 KB |
testcase_23 | AC | 48 ms
62,464 KB |
testcase_24 | AC | 57 ms
68,864 KB |
testcase_25 | AC | 57 ms
68,224 KB |
testcase_26 | AC | 56 ms
68,608 KB |
testcase_27 | AC | 55 ms
66,944 KB |
testcase_28 | AC | 50 ms
62,976 KB |
testcase_29 | AC | 63 ms
74,496 KB |
testcase_30 | AC | 333 ms
76,416 KB |
testcase_31 | AC | 44 ms
59,136 KB |
testcase_32 | AC | 138 ms
75,904 KB |
testcase_33 | AC | 178 ms
75,776 KB |
testcase_34 | AC | 152 ms
76,160 KB |
testcase_35 | AC | 143 ms
76,032 KB |
testcase_36 | AC | 270 ms
76,544 KB |
testcase_37 | AC | 80 ms
75,776 KB |
testcase_38 | AC | 291 ms
76,472 KB |
testcase_39 | AC | 158 ms
75,776 KB |
ソースコード
mod = 10**9+7 k, n = map(int, input().split()) a = list(map(int, input().split())) # 累積和 if n <= 10**6: aa = [0]*n # 1-indexed s = [0]*(n+1) for i in range(k): aa[i] = a[i] s[i+1] = s[i] + a[i] for i in range(k, n): ai = s[i] - s[i-k] aa[i] = ai aa[i] %= mod s[i+1] = s[i] + ai s[i+1] %= mod print(aa[-1], s[-1]) # 行列累乗 else: def mul(a, b): n = len(a) c = [[0]*n for i in range(n)] for i in range(n): for j in range(n): for k in range(n): c[i][j] += (a[i][k]*b[k][j])%mod return c def pow(a, n): b = [[0]*len(a) for i in range(len(a))] for i in range(len(a)): b[i][i] = 1 while n: if n&1: b = mul(a, b) a = mul(a, a) n >>=1 return b A = [[0]*k for i in range(k)] A[0] = [1]*k for i in range(k-1): A[i+1][i] = 1 A = pow(A, n-k) f = 0 for i in range(k): f += A[0][i]*a[k-i-1] f %= mod B = [[0]*(k+1) for i in range(k+1)] B[0][0] = 2 B[0][-1] = -1 for i in range(k): B[i+1][i] = 1 B = pow(B, n-k) from itertools import accumulate s = [0] + list(accumulate(a)) g = 0 for i in range(k+1): g += B[0][i]*s[k-i] g %= mod print(f, g)