結果

問題 No.978 Fibonacci Convolution Easy
ユーザー tadanoningentadanoningen
提出日時 2020-10-08 04:09:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 467 bytes
コンパイル時間 553 ms
コンパイル使用メモリ 76,140 KB
実行使用メモリ 18,772 KB
最終ジャッジ日時 2023-09-27 11:36:12
合計ジャッジ時間 1,690 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 13 ms
9,076 KB
testcase_02 AC 6 ms
6,032 KB
testcase_03 AC 26 ms
18,240 KB
testcase_04 AC 9 ms
6,872 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 11 ms
8,112 KB
testcase_07 AC 21 ms
12,532 KB
testcase_08 AC 13 ms
9,544 KB
testcase_09 AC 21 ms
14,416 KB
testcase_10 AC 29 ms
18,772 KB
testcase_11 AC 10 ms
7,484 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 10 ms
8,152 KB
testcase_14 AC 5 ms
4,376 KB
testcase_15 AC 12 ms
9,076 KB
testcase_16 AC 29 ms
18,508 KB
testcase_17 AC 30 ms
18,692 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#define ll long long
#define mod 1000000007

using namespace std;

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