結果
| 問題 |
No.978 Fibonacci Convolution Easy
|
| ユーザー |
ndifix
|
| 提出日時 | 2020-01-31 22:05:13 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 49 ms / 2,000 ms |
| コード長 | 737 bytes |
| コンパイル時間 | 1,716 ms |
| コンパイル使用メモリ | 168,844 KB |
| 実行使用メモリ | 18,816 KB |
| 最終ジャッジ日時 | 2024-09-18 20:58:48 |
| 合計ジャッジ時間 | 2,720 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 |
ソースコード
#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;
}
ndifix