結果

問題 No.194 フィボナッチ数列の理解(1)
ユーザー cielciel
提出日時 2015-04-27 01:21:03
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 174 ms / 5,000 ms
コード長 1,273 bytes
コンパイル時間 476 ms
コンパイル使用メモリ 64,296 KB
実行使用メモリ 69,056 KB
最終ジャッジ日時 2023-09-18 12:39:29
合計ジャッジ時間 2,500 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 29 ms
4,376 KB
testcase_03 AC 4 ms
4,376 KB
testcase_04 AC 11 ms
4,376 KB
testcase_05 AC 9 ms
4,380 KB
testcase_06 AC 11 ms
4,376 KB
testcase_07 AC 18 ms
4,376 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 14 ms
4,376 KB
testcase_10 AC 6 ms
4,376 KB
testcase_11 AC 7 ms
4,376 KB
testcase_12 AC 9 ms
4,380 KB
testcase_13 AC 4 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 22 ms
4,380 KB
testcase_16 AC 20 ms
4,380 KB
testcase_17 AC 6 ms
4,380 KB
testcase_18 AC 21 ms
4,380 KB
testcase_19 AC 28 ms
4,380 KB
testcase_20 AC 31 ms
14,008 KB
testcase_21 AC 31 ms
12,856 KB
testcase_22 AC 31 ms
11,540 KB
testcase_23 AC 4 ms
4,376 KB
testcase_24 AC 17 ms
7,944 KB
testcase_25 AC 15 ms
9,916 KB
testcase_26 AC 15 ms
9,336 KB
testcase_27 AC 20 ms
10,780 KB
testcase_28 AC 6 ms
4,384 KB
testcase_29 AC 30 ms
16,064 KB
testcase_30 AC 28 ms
4,376 KB
testcase_31 AC 174 ms
69,056 KB
testcase_32 AC 9 ms
4,380 KB
testcase_33 AC 13 ms
4,380 KB
testcase_34 AC 10 ms
4,376 KB
testcase_35 AC 9 ms
4,376 KB
testcase_36 AC 21 ms
4,376 KB
testcase_37 AC 3 ms
4,380 KB
testcase_38 AC 24 ms
4,376 KB
testcase_39 AC 9 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <valarray>
#include <vector>
#include <cstdio>
using namespace std;
typedef valarray<__int128_t>V; //lol
int _N,MOD=1000000007;
V z;
V &Me(const V &_x,const V &_y){
	int i=0,j;
	for(;i<_N;i++)for(j=0;j<_N;j++)z[i*_N+j]=(_x[slice(i*_N,_N,1)]*_y[slice(j,_N,_N)]).sum()%MOD;
	return z;
}
V &Mx(const V &_x){
	int i=0,j;
	for(;i<_N;i++)for(j=0;j<_N;j++)z[i*_N+j]=(_x[slice(i*_N,_N,1)]*_x[slice(j,_N,_N)]).sum()%MOD;
	return z;
}

int main(){
	int N;
	long long K;
	scanf("%d%lld",&N,&K);
	vector<long long>A(N);
	for(int i=0;i<N;i++)scanf("%lld",&A[i]);
	if(K<=10000000){
		long long accum=0;
		for(int i=0;i<N;i++)accum=(accum+A[i])%MOD;
		long long s=accum;
		for(int i=N;i<K;i++){
			A.push_back(accum);
			s=(s+accum)%MOD;
			accum=(accum+A[i]-A[i-N]+MOD)%MOD;
		}
		printf("%lld %lld\n",A[K-1],s);
	}else{
		_N=N*2;
		V x(_N*_N);
		V e(_N*_N);
		z.resize(_N*_N);
		for(int i=0;i<_N;i++)e[i*_N+i]=1;
		for(int i=0;i<N;i++){
			x[i]=1;
			if(i)x[i*_N+i-1]=1;
			x[(i+N)*_N+i]=x[(i+N)*_N+i+N]=1;
		}
		V x0=x;
		for(K--;K;K>>=1){
			if(K&1)e=Me(e,x);
			x=Mx(x);
		}
		long long f=0;
		for(int i=0;i<N;i++)f=(f+e[(N-1)*_N+i]*A[N-i-1])%MOD;
		printf("%lld ",f);
		e=Me(e,x0);
		f=0;
		for(int i=0;i<N;i++)f=(f+e[(2*N-1)*_N+i]*A[N-i-1])%MOD;
		printf("%lld\n",f);
	}
}
0