結果

問題 No.978 Fibonacci Convolution Easy
ユーザー ndifixndifix
提出日時 2020-01-31 22:05:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 737 bytes
コンパイル時間 1,618 ms
コンパイル使用メモリ 169,836 KB
実行使用メモリ 18,940 KB
最終ジャッジ日時 2023-10-19 01:03:08
合計ジャッジ時間 2,821 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 21 ms
9,444 KB
testcase_02 AC 13 ms
6,412 KB
testcase_03 AC 47 ms
18,148 KB
testcase_04 AC 14 ms
7,136 KB
testcase_05 AC 4 ms
4,348 KB
testcase_06 AC 19 ms
8,456 KB
testcase_07 AC 32 ms
13,004 KB
testcase_08 AC 23 ms
9,972 KB
testcase_09 AC 36 ms
14,324 KB
testcase_10 AC 49 ms
18,940 KB
testcase_11 AC 16 ms
7,664 KB
testcase_12 AC 4 ms
4,348 KB
testcase_13 AC 18 ms
8,456 KB
testcase_14 AC 7 ms
4,828 KB
testcase_15 AC 20 ms
9,180 KB
testcase_16 AC 49 ms
18,940 KB
testcase_17 AC 49 ms
18,940 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using LL=long long;
template<class T>void sort(vector<T> &v){sort(v.begin(),v.end());}
template<class T>int lower_bound(vector<T> &v, T key){
	return distance(v.begin(), lower_bound(v.begin(),v.end(),key));
}
template<class T>int upper_bound(vector<T> &v, T key){
	return distance(v.begin(), upper_bound(v.begin(), v.end(), key));
}

int main(){
	const int mod=1000000007;
	int n,p;cin>>n>>p;
	vector<LL> a(n);for(auto &i:a)cin>>i;

	a[0]=0;a[1]=1;
	for(int i=2;i<n;i++)a[i]=(p*a[i-1]+a[i-2])%mod;

	LL sum=0;for(auto i:a)sum=(sum+i)%mod;
	LL tr=0;for(auto i:a)tr=(tr+i*i)%mod;

	LL ans=0;
	ans=sum*sum-tr;
	if(ans%2==1)ans+=mod;
	ans/=2;
	ans+=tr;
	ans%=mod;
	cout<<ans<<endl;
	return 0;
}
0