結果
問題 | No.194 フィボナッチ数列の理解(1) |
ユーザー | toyuzuko |
提出日時 | 2020-07-25 19:35:23 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 84 ms / 5,000 ms |
コード長 | 2,033 bytes |
コンパイル時間 | 1,109 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 76,416 KB |
最終ジャッジ日時 | 2024-06-27 13:44:08 |
合計ジャッジ時間 | 4,303 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
52,096 KB |
testcase_01 | AC | 40 ms
52,224 KB |
testcase_02 | AC | 84 ms
76,160 KB |
testcase_03 | AC | 58 ms
66,048 KB |
testcase_04 | AC | 66 ms
71,168 KB |
testcase_05 | AC | 68 ms
71,296 KB |
testcase_06 | AC | 64 ms
70,528 KB |
testcase_07 | AC | 68 ms
72,832 KB |
testcase_08 | AC | 59 ms
66,048 KB |
testcase_09 | AC | 69 ms
72,704 KB |
testcase_10 | AC | 64 ms
70,656 KB |
testcase_11 | AC | 64 ms
69,248 KB |
testcase_12 | AC | 65 ms
71,296 KB |
testcase_13 | AC | 60 ms
67,200 KB |
testcase_14 | AC | 55 ms
65,024 KB |
testcase_15 | AC | 81 ms
76,288 KB |
testcase_16 | AC | 71 ms
72,704 KB |
testcase_17 | AC | 65 ms
70,400 KB |
testcase_18 | AC | 69 ms
72,704 KB |
testcase_19 | AC | 82 ms
76,416 KB |
testcase_20 | AC | 59 ms
66,688 KB |
testcase_21 | AC | 62 ms
71,424 KB |
testcase_22 | AC | 61 ms
66,688 KB |
testcase_23 | AC | 49 ms
63,872 KB |
testcase_24 | AC | 55 ms
66,688 KB |
testcase_25 | AC | 53 ms
65,920 KB |
testcase_26 | AC | 55 ms
66,688 KB |
testcase_27 | AC | 53 ms
63,360 KB |
testcase_28 | AC | 49 ms
63,104 KB |
testcase_29 | AC | 61 ms
68,224 KB |
testcase_30 | AC | 81 ms
76,160 KB |
testcase_31 | AC | 39 ms
52,736 KB |
testcase_32 | AC | 65 ms
70,656 KB |
testcase_33 | AC | 66 ms
71,168 KB |
testcase_34 | AC | 65 ms
71,040 KB |
testcase_35 | AC | 64 ms
70,528 KB |
testcase_36 | AC | 68 ms
73,088 KB |
testcase_37 | AC | 55 ms
65,408 KB |
testcase_38 | AC | 67 ms
72,704 KB |
testcase_39 | AC | 65 ms
70,784 KB |
ソースコード
from itertools import accumulate MOD = 1000000007 N, K = map(int, input().split()) A = list(map(int, input().split())) C = [0] + list(accumulate(A)) if N <= 10000 and K <= 1000000: res = [0 for _ in range(K)] for i in range(N): res[i] = A[i] res[N] = sum(A) for i in range(N + 1, K): res[i] = res[i - 1] * 2 - res[i - N - 1] res[i] %= MOD print(res[-1], sum(res) % MOD) else: def inc(arr, base): n = len(arr) res = [0 for _ in range(n)] res[0] = arr[n - 1] * base[0] for i in range(1, n): res[i] = arr[i - 1] + arr[n - 1] * base[i] res[i] %= MOD return res def dec(arr, base): n = len(arr) res = [0 for _ in range(n)] res[n - 1] = arr[0] * pow(base[0], MOD - 2, MOD) for i in range(n - 1)[::-1]: res[i] = arr[i + 1] - res[n - 1] * base[i + 1] res[i] %= MOD return res def dub(arr, base): n = len(arr) res = [0 for _ in range(n)] tmp = [arr] for i in range(n - 1): tmp.append(inc(tmp[-1], base)) for i in range(n): for j in range(n): res[i] += tmp[0][j] * tmp[j][i] res[i] %= MOD return res res = [1 for _ in range(N)] exp = K - 1 base = [1 for _ in range(N)] for _ in range(N): res = dec(res, base) for bit in range(exp.bit_length())[::-1]: res = dub(res, base) if (exp >> bit) & 1: res = inc(res, base) F = sum([res[i] * A[i] for i in range(N)]) % MOD res = [0 for _ in range(N + 1)] res[0] = -1 res[-1] = 2 base = [0 for _ in range(N + 1)] base[0] = -1 base[-1] = 2 exp = K for _ in range(N + 1): res = dec(res, base) for bit in range(exp.bit_length())[::-1]: res = dub(res, base) if (exp >> bit) & 1: res = inc(res, base) S = sum([res[i] * C[i] for i in range(N + 1)]) % MOD print(F, S)