結果

問題 No.978 Fibonacci Convolution Easy
ユーザー snow39snow39
提出日時 2020-01-31 21:53:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 603 bytes
コンパイル時間 803 ms
コンパイル使用メモリ 93,720 KB
実行使用メモリ 19,048 KB
最終ジャッジ日時 2023-10-19 01:00:37
合計ジャッジ時間 1,920 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 17 ms
9,552 KB
testcase_02 AC 11 ms
6,520 KB
testcase_03 AC 37 ms
18,256 KB
testcase_04 AC 12 ms
7,244 KB
testcase_05 AC 4 ms
4,348 KB
testcase_06 AC 16 ms
8,564 KB
testcase_07 AC 25 ms
13,112 KB
testcase_08 AC 19 ms
10,080 KB
testcase_09 AC 29 ms
14,432 KB
testcase_10 AC 39 ms
19,048 KB
testcase_11 AC 14 ms
7,772 KB
testcase_12 AC 4 ms
4,348 KB
testcase_13 AC 15 ms
8,564 KB
testcase_14 AC 6 ms
4,936 KB
testcase_15 AC 16 ms
9,288 KB
testcase_16 AC 39 ms
19,048 KB
testcase_17 AC 39 ms
19,048 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 <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

int main(){
  int N;
  ll P;
  cin>>N>>P;

  vector<ll> A(N,0);
  A[0]=0;
  A[1]=1;
  for(int i=2;i<N;i++) A[i]=(P*A[i-1]%MOD+A[i-2])%MOD;

  ll sum=0;
  ll ans=0;
  rep(i,N){
    sum=(sum+A[i])%MOD;
    ans=(ans+sum*A[i]%MOD)%MOD;
  }

  cout<<ans<<endl;

  return 0;
}
0