結果

問題 No.978 Fibonacci Convolution Easy
ユーザー hanbei_dayohanbei_dayo
提出日時 2020-02-01 02:04:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 699 bytes
コンパイル時間 735 ms
コンパイル使用メモリ 81,764 KB
実行使用メモリ 19,260 KB
最終ジャッジ日時 2023-10-19 01:08:53
合計ジャッジ時間 1,911 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 16 ms
10,448 KB
testcase_02 AC 10 ms
8,400 KB
testcase_03 AC 37 ms
18,640 KB
testcase_04 AC 11 ms
8,400 KB
testcase_05 AC 5 ms
6,352 KB
testcase_06 AC 14 ms
10,448 KB
testcase_07 AC 25 ms
14,544 KB
testcase_08 AC 18 ms
10,448 KB
testcase_09 AC 28 ms
16,592 KB
testcase_10 AC 38 ms
19,228 KB
testcase_11 AC 12 ms
8,400 KB
testcase_12 AC 4 ms
6,352 KB
testcase_13 AC 15 ms
10,448 KB
testcase_14 AC 6 ms
6,352 KB
testcase_15 AC 16 ms
10,448 KB
testcase_16 AC 39 ms
19,260 KB
testcase_17 AC 38 ms
19,212 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<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<math.h>
using namespace std;
#define mod (1000000000+7)
#define N (10007)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;

ll dp[2000010];

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