結果

問題 No.194 フィボナッチ数列の理解(1)
ユーザー GoryudyumaGoryudyuma
提出日時 2015-06-17 23:20:17
言語 C++11
(gcc 11.4.0)
結果
MLE  
実行時間 -
コード長 2,753 bytes
コンパイル時間 1,096 ms
コンパイル使用メモリ 131,748 KB
実行使用メモリ 814,400 KB
最終ジャッジ日時 2023-09-21 09:24:19
合計ジャッジ時間 3,510 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 21 ms
4,376 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 9 ms
4,376 KB
testcase_05 AC 7 ms
4,376 KB
testcase_06 AC 9 ms
4,376 KB
testcase_07 AC 14 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 11 ms
4,376 KB
testcase_10 AC 5 ms
4,376 KB
testcase_11 AC 5 ms
4,380 KB
testcase_12 AC 7 ms
4,380 KB
testcase_13 AC 4 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 17 ms
4,376 KB
testcase_16 AC 14 ms
4,380 KB
testcase_17 AC 4 ms
4,380 KB
testcase_18 AC 14 ms
4,376 KB
testcase_19 AC 20 ms
4,380 KB
testcase_20 AC 2 ms
4,380 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 #

#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

//#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
//#endif

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#include <array>
//#include <atomic>
#include <chrono>
//#include <condition_variable>
#include <forward_list>
//#include <future>
#include <initializer_list>
//#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
//#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>


using namespace std;

typedef long long ll;
typedef vector<ll>vec;
typedef vector<vec>mat;

// A*Bの計算
mat mul ( mat &A , mat&B , ll M )
{
	mat C ( A.size () , vec ( B[0].size () ) );
	for( int i = 0; i < A.size (); i++ )
	{
		for( int k = 0; k < B.size (); k++ )
		{
			for( int j = 0; j < B[0].size (); j++ )
			{
				C[i][j] = ( C[i][j] + A[i][k] * B[k][j] ) % M;
			}
		}
	}
	return C;
}
// A^nの計算
mat pow ( mat A , ll n , ll M )
{
	mat B ( A.size () , vec ( A.size () ) );
	for( int i = 0; i < A.size (); i++ )
	{
		B[i][i] = 1;
	}
	while( n > 0 )
	{
		if( n & 1 ) B = mul ( B , A , M );
		A = mul ( A , A , M );
		n >>= 1;
	}
	return B;
}

//初期化
//mat A(2, vec(2));

int main ()
{
	long long int N , K;
	cin >> N >> K;
	mat A ( N + 1 , vec ( N + 1 ) );
	for( size_t i = 0; i < N - 1; i++ )
	{
		A[i][i + 1] = 1;
	}
	for( int i = 0; i < N; i++ )
	{
		A[N - 1][N - i - 1] = 1;
		A[N][i] = 1;
	}
	A[N][N] = 1;
	mat B ( N + 1 , vec ( 1 ) );
	for( size_t i = 0; i < N; i++ )
	{
		cin >> B[i][0];
	}
	for( size_t i = 0; i < N; i++ )
	{
		B[N][0] += B[i][0];
	}
	mat D = pow ( A , K - N , ( long long int )1e9 + 7 );
	mat C = mul ( D , B , ( long long int )1e9 + 7 );
	cout << C[N - 1][0] << " " << C[N][0] << endl;
	return 0;
}
0