結果

問題 No.194 フィボナッチ数列の理解(1)
ユーザー toyuzukotoyuzuko
提出日時 2020-07-25 19:34:30
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 2,042 bytes
コンパイル時間 1,242 ms
コンパイル使用メモリ 86,580 KB
実行使用メモリ 827,472 KB
最終ジャッジ日時 2023-09-09 21:13:49
合計ジャッジ時間 8,535 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,364 KB
testcase_01 AC 76 ms
71,296 KB
testcase_02 AC 119 ms
77,536 KB
testcase_03 AC 94 ms
76,040 KB
testcase_04 AC 102 ms
76,944 KB
testcase_05 AC 103 ms
76,980 KB
testcase_06 AC 100 ms
77,060 KB
testcase_07 AC 106 ms
77,296 KB
testcase_08 AC 94 ms
76,168 KB
testcase_09 AC 104 ms
77,472 KB
testcase_10 AC 101 ms
77,028 KB
testcase_11 AC 100 ms
77,264 KB
testcase_12 AC 100 ms
77,188 KB
testcase_13 AC 95 ms
76,584 KB
testcase_14 AC 92 ms
76,316 KB
testcase_15 AC 116 ms
76,980 KB
testcase_16 AC 108 ms
77,296 KB
testcase_17 AC 103 ms
77,000 KB
testcase_18 AC 104 ms
77,324 KB
testcase_19 AC 115 ms
77,692 KB
testcase_20 AC 88 ms
76,248 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 -- -
権限があれば一括ダウンロードができます

ソースコード

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 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)
0