結果

問題 No.978 Fibonacci Convolution Easy
ユーザー shop_oneshop_one
提出日時 2020-01-31 21:38:50
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 36 ms / 2,000 ms
コード長 725 bytes
コンパイル時間 860 ms
コンパイル使用メモリ 84,252 KB
実行使用メモリ 34,460 KB
最終ジャッジ日時 2023-10-19 00:57:08
合計ジャッジ時間 2,155 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 17 ms
15,272 KB
testcase_02 AC 10 ms
9,404 KB
testcase_03 AC 35 ms
33,208 KB
testcase_04 AC 12 ms
10,724 KB
testcase_05 AC 4 ms
4,720 KB
testcase_06 AC 14 ms
13,756 KB
testcase_07 AC 24 ms
22,476 KB
testcase_08 AC 18 ms
16,592 KB
testcase_09 AC 26 ms
25,492 KB
testcase_10 AC 36 ms
34,460 KB
testcase_11 AC 13 ms
11,976 KB
testcase_12 AC 4 ms
4,456 KB
testcase_13 AC 15 ms
13,492 KB
testcase_14 AC 6 ms
6,040 KB
testcase_15 AC 16 ms
15,076 KB
testcase_16 AC 35 ms
34,460 KB
testcase_17 AC 36 ms
34,196 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 #

// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
#define MOD 1000000007
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
signed main(){
  init_io();
  ll n,p,ans=0;
  cin >> n >> p;
  vector<ll> a(n+1),sum(n+2);
  a[0] = 0;
  a[1] = 1;
  sum[0] = 0;
  sum[1] = 1;
  for(int i=2;i<=n;i++){
    a[i] = p*a[i-1] + a[i-2];
    a[i] %= MOD;
    sum[i] = sum[i-1] + a[i];
    sum[i] %= MOD;
  }
  for(int i=n-1;i>=0;i--){
    ans += (sum[i]*a[i])%MOD;
    ans %= MOD;
  }
  cout << ans << endl;
}
0