結果
問題 | No.194 フィボナッチ数列の理解(1) |
ユーザー | yaoshimax |
提出日時 | 2015-05-15 00:59:19 |
言語 | PyPy2 (7.3.15) |
結果 |
AC
|
実行時間 | 139 ms / 5,000 ms |
コード長 | 1,843 bytes |
コンパイル時間 | 1,363 ms |
コンパイル使用メモリ | 76,580 KB |
実行使用メモリ | 79,368 KB |
最終ジャッジ日時 | 2024-07-06 03:46:39 |
合計ジャッジ時間 | 6,880 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 78 ms
75,304 KB |
testcase_01 | AC | 76 ms
75,704 KB |
testcase_02 | AC | 139 ms
78,620 KB |
testcase_03 | AC | 105 ms
77,964 KB |
testcase_04 | AC | 120 ms
78,880 KB |
testcase_05 | AC | 113 ms
78,600 KB |
testcase_06 | AC | 117 ms
78,524 KB |
testcase_07 | AC | 129 ms
78,652 KB |
testcase_08 | AC | 102 ms
77,976 KB |
testcase_09 | AC | 126 ms
78,628 KB |
testcase_10 | AC | 110 ms
78,756 KB |
testcase_11 | AC | 114 ms
79,164 KB |
testcase_12 | AC | 116 ms
79,368 KB |
testcase_13 | AC | 108 ms
77,988 KB |
testcase_14 | AC | 96 ms
77,740 KB |
testcase_15 | AC | 128 ms
78,784 KB |
testcase_16 | AC | 124 ms
78,896 KB |
testcase_17 | AC | 107 ms
79,120 KB |
testcase_18 | AC | 128 ms
78,868 KB |
testcase_19 | AC | 131 ms
79,168 KB |
testcase_20 | AC | 97 ms
77,960 KB |
testcase_21 | AC | 102 ms
78,360 KB |
testcase_22 | AC | 75 ms
75,784 KB |
testcase_23 | AC | 85 ms
78,008 KB |
testcase_24 | AC | 92 ms
77,828 KB |
testcase_25 | AC | 93 ms
78,112 KB |
testcase_26 | AC | 92 ms
77,984 KB |
testcase_27 | AC | 88 ms
76,680 KB |
testcase_28 | AC | 85 ms
77,736 KB |
testcase_29 | AC | 101 ms
78,488 KB |
testcase_30 | AC | 130 ms
78,888 KB |
testcase_31 | AC | 76 ms
75,804 KB |
testcase_32 | AC | 112 ms
79,140 KB |
testcase_33 | AC | 118 ms
78,756 KB |
testcase_34 | AC | 119 ms
78,880 KB |
testcase_35 | AC | 113 ms
78,724 KB |
testcase_36 | AC | 129 ms
78,472 KB |
testcase_37 | AC | 101 ms
77,836 KB |
testcase_38 | AC | 131 ms
78,780 KB |
testcase_39 | AC | 112 ms
78,764 KB |
ソースコード
N,K=map(int,raw_input().split()) A=map(int,raw_input().split()) mod=1000000007 s=sum(A) S=sum(A) if N>30: for i in range(N,K): s-=A[i%N] A[i%N]=s+A[i%N] A[i%N]%=mod s+=A[i%N] S+=A[i%N] S%=mod s%=mod print A[(K-1)%N],S else: mat=[[0 for i in range(N+1)] for j in range(N+1)] for i in range(N): mat[i][i+1]=1 mat[N][N]=2 mat[N][0]-=1 vec=[0 for i in range(N+1)] vec[0]=0 for i in range(1,N+1): vec[i]=A[i-1]+vec[i-1] m=[[0 for i in range(N+1)] for j in range(N+1)] for i in range(N+1): m[i][i]=1 K-=N while K>0: # for i in range(N+1): # for j in range(N+1): # print m[i][j], # print " ", # for j in range(N+1): # print mat[i][j], # print " ", # print vec[i] # print if K%2==1: m2=[[0 for i in range(N+1)] for j in range(N+1)] for i in range(N+1): for j in range(N+1): for k in range(N+1): m2[i][j]+=mat[i][k]*m[k][j] m2[i][j]%=mod m = m2 mat2=[[0 for i in range(N+1)] for j in range(N+1)] for i in range(N+1): for j in range(N+1): for k in range(N+1): mat2[i][j]+=mat[i][k]*mat[k][j] mat2[i][j]%=mod mat=mat2 K/=2 ans =0 ans2 =0 #for i in range(N+1): # for j in range(N+1): # print m[i][j], # print " ", # for j in range(N+1): # print mat[i][j], # print # print for i in range(N+1): ans+=m[N][i]*vec[i] ans2+=m[N-1][i]*vec[i] ans%=mod ans2%=mod print (ans-ans2)%mod, ans