結果

問題 No.978 Fibonacci Convolution Easy
ユーザー totori_nyaatotori_nyaa
提出日時 2020-01-31 21:39:35
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 47 ms / 2,000 ms
コード長 607 bytes
コンパイル時間 1,506 ms
コンパイル使用メモリ 167,780 KB
実行使用メモリ 19,164 KB
最終ジャッジ日時 2023-10-19 00:57:14
合計ジャッジ時間 2,718 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 20 ms
10,352 KB
testcase_02 AC 11 ms
8,304 KB
testcase_03 AC 44 ms
18,544 KB
testcase_04 AC 13 ms
8,304 KB
testcase_05 AC 5 ms
6,256 KB
testcase_06 AC 18 ms
10,352 KB
testcase_07 AC 30 ms
14,448 KB
testcase_08 AC 22 ms
10,352 KB
testcase_09 AC 35 ms
16,496 KB
testcase_10 AC 47 ms
19,132 KB
testcase_11 AC 15 ms
8,304 KB
testcase_12 AC 4 ms
6,256 KB
testcase_13 AC 17 ms
10,352 KB
testcase_14 AC 7 ms
6,256 KB
testcase_15 AC 19 ms
10,352 KB
testcase_16 AC 47 ms
19,164 KB
testcase_17 AC 46 ms
19,116 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

ll a[2000010];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    ll n,p;
    cin>>n>>p;
    ll mod = 1e9+7;
    a[0]=0,a[1]=1;
    for(int i=2;i<n;i++){
        a[i] = (p*a[i-1])%mod + a[i-2];
        a[i] %= mod;
    }
    ll ans = 0;
    ll sum = 0;
    for(int i=0;i<n;i++){
        sum += a[i];
        sum %= mod;
    }
    for(int i=0;i<n;i++){
        ans += (sum * a[i])%mod;
        sum += mod - a[i];
        ans %= mod;
        sum %= mod;
    }
    cout << ans << endl;
}
0