結果

問題 No.978 Fibonacci Convolution Easy
ユーザー どららどらら
提出日時 2020-01-31 22:52:56
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 40 ms / 2,000 ms
コード長 694 bytes
コンパイル時間 1,551 ms
コンパイル使用メモリ 167,048 KB
実行使用メモリ 34,772 KB
最終ジャッジ日時 2023-10-19 01:06:10
合計ジャッジ時間 2,676 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,748 KB
testcase_01 AC 17 ms
18,528 KB
testcase_02 AC 10 ms
12,384 KB
testcase_03 AC 39 ms
34,132 KB
testcase_04 AC 12 ms
14,432 KB
testcase_05 AC 5 ms
8,288 KB
testcase_06 AC 16 ms
16,480 KB
testcase_07 AC 26 ms
26,720 KB
testcase_08 AC 18 ms
18,528 KB
testcase_09 AC 29 ms
28,768 KB
testcase_10 AC 40 ms
34,740 KB
testcase_11 AC 14 ms
14,432 KB
testcase_12 AC 5 ms
8,288 KB
testcase_13 AC 15 ms
16,480 KB
testcase_14 AC 7 ms
10,336 KB
testcase_15 AC 17 ms
18,528 KB
testcase_16 AC 39 ms
34,772 KB
testcase_17 AC 40 ms
34,724 KB
testcase_18 AC 2 ms
5,572 KB
testcase_19 AC 2 ms
5,572 KB
testcase_20 AC 2 ms
5,572 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

static const ll MOD = 1000000007;

ll A[2000005];
ll B[2000005];

int main(){
  ll N, p;
  cin >> N >> p;

  A[1] = 0; B[1] = 0;
  A[2] = 1; B[2] = 1;
  REP(i,3,N+1){
    A[i] = ((p * A[i-1])%MOD) + A[i-2];
    A[i] %= MOD;
    B[i] = B[i-1] + A[i];
    B[i] %= MOD;
  }

  ll ret = 0;
  REP(i,1,N+1){
    ret += (A[i] * B[i])%MOD;
    ret %= MOD;
  }

  cout << ret << endl;
  
  return 0;
}
0