結果

問題 No.194 フィボナッチ数列の理解(1)
ユーザー 👑 rin204rin204
提出日時 2022-03-25 20:52:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 178 ms / 5,000 ms
コード長 1,136 bytes
コンパイル時間 395 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 217,600 KB
最終ジャッジ日時 2024-04-22 05:32:37
合計ジャッジ時間 5,257 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
53,248 KB
testcase_01 AC 43 ms
53,376 KB
testcase_02 AC 94 ms
76,416 KB
testcase_03 AC 72 ms
70,016 KB
testcase_04 AC 82 ms
73,728 KB
testcase_05 AC 78 ms
73,472 KB
testcase_06 AC 80 ms
75,264 KB
testcase_07 AC 89 ms
76,416 KB
testcase_08 AC 72 ms
70,784 KB
testcase_09 AC 92 ms
76,672 KB
testcase_10 AC 80 ms
71,552 KB
testcase_11 AC 74 ms
71,936 KB
testcase_12 AC 88 ms
73,216 KB
testcase_13 AC 80 ms
72,320 KB
testcase_14 AC 69 ms
68,224 KB
testcase_15 AC 91 ms
76,544 KB
testcase_16 AC 91 ms
76,288 KB
testcase_17 AC 74 ms
71,424 KB
testcase_18 AC 91 ms
76,288 KB
testcase_19 AC 96 ms
76,544 KB
testcase_20 AC 175 ms
215,296 KB
testcase_21 AC 178 ms
217,600 KB
testcase_22 AC 172 ms
209,792 KB
testcase_23 AC 60 ms
67,840 KB
testcase_24 AC 112 ms
135,040 KB
testcase_25 AC 105 ms
125,824 KB
testcase_26 AC 105 ms
126,336 KB
testcase_27 AC 114 ms
137,472 KB
testcase_28 AC 66 ms
79,360 KB
testcase_29 AC 157 ms
191,872 KB
testcase_30 AC 96 ms
76,672 KB
testcase_31 AC 45 ms
53,888 KB
testcase_32 AC 86 ms
76,416 KB
testcase_33 AC 91 ms
76,928 KB
testcase_34 AC 79 ms
73,472 KB
testcase_35 AC 88 ms
76,288 KB
testcase_36 AC 90 ms
76,544 KB
testcase_37 AC 73 ms
71,424 KB
testcase_38 AC 89 ms
76,544 KB
testcase_39 AC 79 ms
74,496 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from copy import deepcopy
MOD = 10 ** 9 + 7

def matpow(A, B, w):
    l = len(A)
    while w:
        if w & 1:
            C = [0] * l
            for i in range(l):
                for j in range(l):
                    C[i] += A[i][j] * B[j]
                    C[i] %= MOD
            B = C.copy()
        C = [[0] * l for _ in range(l)]
        for i in range(l):
            for j in range(l):
                for k in range(l):
                    C[i][j] += A[i][k] * A[k][j]
                    C[i][j] %= MOD
        A = deepcopy(C)
        w >>= 1
    return B

n, k = map(int, input().split())
A = list(map(int, input().split()))

if k <= 10 ** 6:
    A = [0] + A
    cum = A[:]
    for i in range(1, n + 1):
        cum[i] += cum[i - 1]
    for _ in range(n + 1, k + 1):
        A.append((cum[-1] - cum[-n - 1]) % MOD)
        cum.append((cum[-1] + A[-1]) % MOD)
    print(A[-1], cum[-1])
    
else:
    B = A[::-1] + [0]
    A = [[0] * (n + 1) for _ in range(n + 1)]
    for i in range(n):
        A[0][i] = 1
        A[i + 1][i] = 1
    A[n][n] = 1
    B = matpow(A, B, k - n)
    print(B[0], sum(B) % MOD)
    
    
    
0