結果
問題 | No.194 フィボナッチ数列の理解(1) |
ユーザー | Navier_Boltzmann |
提出日時 | 2022-10-11 04:58:49 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 142 ms / 5,000 ms |
コード長 | 1,854 bytes |
コンパイル時間 | 147 ms |
コンパイル使用メモリ | 82,508 KB |
実行使用メモリ | 77,504 KB |
最終ジャッジ日時 | 2024-06-25 01:29:47 |
合計ジャッジ時間 | 5,141 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 53 ms
56,576 KB |
testcase_01 | AC | 53 ms
63,808 KB |
testcase_02 | AC | 140 ms
77,504 KB |
testcase_03 | AC | 78 ms
77,000 KB |
testcase_04 | AC | 99 ms
76,808 KB |
testcase_05 | AC | 101 ms
76,700 KB |
testcase_06 | AC | 102 ms
76,704 KB |
testcase_07 | AC | 114 ms
76,956 KB |
testcase_08 | AC | 78 ms
76,832 KB |
testcase_09 | AC | 106 ms
76,992 KB |
testcase_10 | AC | 89 ms
76,632 KB |
testcase_11 | AC | 88 ms
76,824 KB |
testcase_12 | AC | 97 ms
76,632 KB |
testcase_13 | AC | 82 ms
76,756 KB |
testcase_14 | AC | 77 ms
76,712 KB |
testcase_15 | AC | 125 ms
76,864 KB |
testcase_16 | AC | 120 ms
77,060 KB |
testcase_17 | AC | 88 ms
76,792 KB |
testcase_18 | AC | 121 ms
76,988 KB |
testcase_19 | AC | 138 ms
77,248 KB |
testcase_20 | AC | 68 ms
74,412 KB |
testcase_21 | AC | 68 ms
73,936 KB |
testcase_22 | AC | 49 ms
57,840 KB |
testcase_23 | AC | 54 ms
66,800 KB |
testcase_24 | AC | 60 ms
68,344 KB |
testcase_25 | AC | 59 ms
69,012 KB |
testcase_26 | AC | 58 ms
68,940 KB |
testcase_27 | AC | 57 ms
66,988 KB |
testcase_28 | AC | 55 ms
65,652 KB |
testcase_29 | AC | 66 ms
71,164 KB |
testcase_30 | AC | 142 ms
76,864 KB |
testcase_31 | AC | 52 ms
58,176 KB |
testcase_32 | AC | 100 ms
76,788 KB |
testcase_33 | AC | 105 ms
76,952 KB |
testcase_34 | AC | 100 ms
77,072 KB |
testcase_35 | AC | 98 ms
76,864 KB |
testcase_36 | AC | 122 ms
77,076 KB |
testcase_37 | AC | 77 ms
76,656 KB |
testcase_38 | AC | 128 ms
77,196 KB |
testcase_39 | AC | 98 ms
77,108 KB |
ソースコード
from collections import * from itertools import * from functools import * from heapq import * import sys,math input = sys.stdin.readline N,K = map(int,input().split()) A = list(map(int,input().split())) mod = 10**9 + 7 def answer1(): dp = [0]*(K) for i in range(N): dp[i] = A[i] S = sum(dp)%mod for i in range(N,K): dp[i] = S S += dp[i] - dp[i-N] S %= mod print(dp[-1],sum(dp)%mod) def matrix_mul(A,B,mod = None): nA = len(A) mA = len(A[0]) mB = len(B[0]) tmp = [[0]*mB for _ in range(nA)] if mod is None: for i in range(nA): for j in range(mB): tmp[i][j] = sum(A[i][k]*B[k][j] for k in range(mA)) return tmp for i in range(nA): for j in range(mB): tmp[i][j] = sum(A[i][k]*B[k][j]%mod for k in range(mA))%mod return tmp def matrix_pow(A,n,mod = None): nbit = list(str(bin(n))[2:]) nbit = [int(i) for i in nbit] N = len(A) C = [[0]*N for _ in range(N)] B = A for i in range(N): C[i][i] = 1 if mod is None: for i in range(len(nbit)): if nbit[-1-i] == 1: C = matrix_mul(C,B) B = matrix_mul(B,B) return C for i in range(len(nbit)): if nbit[-1-i] == 1: C = matrix_mul(C,B,mod) B = matrix_mul(B,B,mod) return C def answer2(): I = [[A[i]] for i in range(N)] + [[A[0]]] X = [[0]*(N+1) for _ in range(N+1)] for i in range(N-1): X[i][i+1] = 1 for i in range(N): X[-2][i]=1 X[-1][1]=1 X[-1][-1]=1 Y = matrix_pow(X,K-1,mod=mod) Z = matrix_mul(Y,I,mod=mod) print(Z[0][0],Z[-1][0]) if N<50: answer2() else: answer1()