結果

問題 No.978 Fibonacci Convolution Easy
ユーザー otamay6otamay6
提出日時 2020-01-31 21:50:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 613 bytes
コンパイル時間 1,552 ms
コンパイル使用メモリ 169,532 KB
実行使用メモリ 34,592 KB
最終ジャッジ日時 2023-10-19 01:00:02
合計ジャッジ時間 2,789 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 18 ms
15,404 KB
testcase_02 AC 11 ms
9,536 KB
testcase_03 AC 41 ms
33,340 KB
testcase_04 AC 13 ms
10,788 KB
testcase_05 AC 5 ms
4,852 KB
testcase_06 AC 17 ms
13,888 KB
testcase_07 AC 28 ms
22,592 KB
testcase_08 AC 22 ms
16,724 KB
testcase_09 AC 31 ms
25,624 KB
testcase_10 AC 41 ms
34,592 KB
testcase_11 AC 15 ms
12,108 KB
testcase_12 AC 5 ms
4,588 KB
testcase_13 AC 16 ms
13,624 KB
testcase_14 AC 7 ms
6,172 KB
testcase_15 AC 19 ms
15,140 KB
testcase_16 AC 41 ms
34,592 KB
testcase_17 AC 42 ms
34,356 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>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    ll mod=1e9+7;
    ll N,p;
    cin>>N>>p;
    vector<ll> a(N);
    a[0]=0,a[1]=1;
    rep(i,2,N){
        a[i]=p*a[i-1]+a[i-2];
        a[i]%=mod;
    }
    vector<ll> S(N+1);
    REP(i,N){
        S[i+1]=S[i]+a[i];
        S[i+1]%=mod;
    }
    ll ans=0;
    REP(i,N){
        ans+=a[i]*S[i+1];
        ans%=mod;
    }
    cout<<ans<<endl;
}
0