結果

問題 No.194 フィボナッチ数列の理解(1)
ユーザー toyuzukotoyuzuko
提出日時 2020-07-25 19:44:35
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 636 ms / 5,000 ms
コード長 1,856 bytes
コンパイル時間 90 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 50,304 KB
最終ジャッジ日時 2024-06-27 13:56:33
合計ジャッジ時間 6,334 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
11,008 KB
testcase_01 AC 30 ms
11,008 KB
testcase_02 AC 65 ms
10,880 KB
testcase_03 AC 38 ms
10,880 KB
testcase_04 AC 49 ms
10,880 KB
testcase_05 AC 45 ms
11,008 KB
testcase_06 AC 46 ms
10,880 KB
testcase_07 AC 55 ms
11,008 KB
testcase_08 AC 35 ms
11,008 KB
testcase_09 AC 50 ms
10,880 KB
testcase_10 AC 38 ms
10,880 KB
testcase_11 AC 44 ms
10,880 KB
testcase_12 AC 44 ms
10,880 KB
testcase_13 AC 38 ms
10,880 KB
testcase_14 AC 33 ms
11,008 KB
testcase_15 AC 62 ms
10,880 KB
testcase_16 AC 56 ms
11,008 KB
testcase_17 AC 40 ms
10,880 KB
testcase_18 AC 55 ms
10,880 KB
testcase_19 AC 62 ms
11,008 KB
testcase_20 AC 490 ms
18,944 KB
testcase_21 AC 632 ms
50,304 KB
testcase_22 AC 636 ms
50,048 KB
testcase_23 AC 53 ms
12,800 KB
testcase_24 AC 301 ms
29,696 KB
testcase_25 AC 285 ms
28,160 KB
testcase_26 AC 288 ms
27,392 KB
testcase_27 AC 356 ms
32,128 KB
testcase_28 AC 98 ms
15,616 KB
testcase_29 AC 580 ms
46,848 KB
testcase_30 AC 62 ms
10,880 KB
testcase_31 AC 30 ms
11,008 KB
testcase_32 AC 44 ms
10,880 KB
testcase_33 AC 47 ms
11,008 KB
testcase_34 AC 44 ms
10,880 KB
testcase_35 AC 44 ms
11,008 KB
testcase_36 AC 57 ms
11,008 KB
testcase_37 AC 34 ms
11,008 KB
testcase_38 AC 57 ms
11,008 KB
testcase_39 AC 45 ms
10,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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(coeff, base):
        n = len(coeff)
        res = [0 for _ in range(n)]
        res[0] = coeff[n - 1] * base[0]
        for i in range(1, n):
            res[i] = coeff[i - 1] + coeff[n - 1] * base[i]
            res[i] %= MOD
        return res

    def dec(coeff, base):
        n = len(coeff)
        res = [0 for _ in range(n)]
        res[n - 1] = coeff[0] * pow(base[0], MOD - 2, MOD)
        for i in range(n - 1)[::-1]:
            res[i] = coeff[i + 1] - res[n - 1] * base[i + 1]
            res[i] %= MOD
        return res

    def dub(coeff, base):
        n = len(coeff)
        res = [0 for _ in range(n)]
        tmp = [coeff]
        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

    def solve(base, arr, exp):
        coeff = base[:]
        n = len(coeff)
        for _ in range(n):
            coeff = dec(coeff, base)

        for bit in range(exp.bit_length())[::-1]:
            coeff = dub(coeff, base)
            if (exp >> bit) & 1:
                coeff = inc(coeff, base)

        return sum([coeff[i] * arr[i] for i in range(n)]) % MOD

    base = [1 for _ in range(N)]
    F = solve(base, A, K - 1)

    base = [0 for _ in range(N + 1)]
    base[0] = -1
    base[-1] = 2
    S = solve(base, C, K)

    print(F, S)
0