結果
問題 | No.194 フィボナッチ数列の理解(1) |
ユーザー | ciel |
提出日時 | 2015-04-27 01:20:05 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,269 bytes |
コンパイル時間 | 493 ms |
コンパイル使用メモリ | 64,004 KB |
実行使用メモリ | 69,972 KB |
最終ジャッジ日時 | 2023-09-18 12:39:26 |
合計ジャッジ時間 | 2,834 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,376 KB |
testcase_01 | AC | 1 ms
4,380 KB |
testcase_02 | AC | 29 ms
4,564 KB |
testcase_03 | AC | 4 ms
4,376 KB |
testcase_04 | AC | 11 ms
4,376 KB |
testcase_05 | AC | 9 ms
4,376 KB |
testcase_06 | AC | 11 ms
4,376 KB |
testcase_07 | AC | 18 ms
4,380 KB |
testcase_08 | AC | 3 ms
4,380 KB |
testcase_09 | AC | 14 ms
4,376 KB |
testcase_10 | AC | 6 ms
4,380 KB |
testcase_11 | AC | 6 ms
4,376 KB |
testcase_12 | AC | 9 ms
4,376 KB |
testcase_13 | AC | 4 ms
4,384 KB |
testcase_14 | AC | 2 ms
4,376 KB |
testcase_15 | AC | 22 ms
4,376 KB |
testcase_16 | AC | 20 ms
4,376 KB |
testcase_17 | AC | 5 ms
4,376 KB |
testcase_18 | AC | 20 ms
4,380 KB |
testcase_19 | AC | 28 ms
4,376 KB |
testcase_20 | AC | 32 ms
13,524 KB |
testcase_21 | AC | 33 ms
13,276 KB |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | AC | 16 ms
8,956 KB |
testcase_27 | AC | 19 ms
10,752 KB |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | AC | 29 ms
4,380 KB |
testcase_31 | WA | - |
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 | 10 ms
4,376 KB |
testcase_36 | AC | 21 ms
4,376 KB |
testcase_37 | AC | 3 ms
4,376 KB |
testcase_38 | AC | 24 ms
4,376 KB |
testcase_39 | AC | 9 ms
4,380 KB |
ソースコード
#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; } 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); } }