結果
問題 | No.194 フィボナッチ数列の理解(1) |
ユーザー | toyuzuko |
提出日時 | 2020-07-25 19:34:30 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
|
実行時間 | - |
コード長 | 2,042 bytes |
コンパイル時間 | 615 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 852,096 KB |
最終ジャッジ日時 | 2024-06-27 13:42:30 |
合計ジャッジ時間 | 6,577 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
53,120 KB |
testcase_01 | AC | 39 ms
52,820 KB |
testcase_02 | AC | 84 ms
76,360 KB |
testcase_03 | AC | 58 ms
66,432 KB |
testcase_04 | AC | 67 ms
71,040 KB |
testcase_05 | AC | 70 ms
71,808 KB |
testcase_06 | AC | 65 ms
70,656 KB |
testcase_07 | AC | 69 ms
72,960 KB |
testcase_08 | AC | 58 ms
66,432 KB |
testcase_09 | AC | 69 ms
72,832 KB |
testcase_10 | AC | 66 ms
71,040 KB |
testcase_11 | AC | 64 ms
69,632 KB |
testcase_12 | AC | 67 ms
71,296 KB |
testcase_13 | AC | 61 ms
67,584 KB |
testcase_14 | AC | 56 ms
65,408 KB |
testcase_15 | AC | 81 ms
76,672 KB |
testcase_16 | AC | 69 ms
72,960 KB |
testcase_17 | AC | 67 ms
71,040 KB |
testcase_18 | AC | 69 ms
73,088 KB |
testcase_19 | AC | 84 ms
76,416 KB |
testcase_20 | AC | 55 ms
64,000 KB |
testcase_21 | MLE | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
ソースコード
from itertools import accumulate MOD = 1000000007 N, K = map(int, input().split()) A = list(map(int, input().split())) C = [0] + list(accumulate(A)) if 1==2 and 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)