結果

問題 No.978 Fibonacci Convolution Easy
ユーザー i_mrhji_mrhj
提出日時 2020-03-22 13:14:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 152 ms / 2,000 ms
コード長 1,096 bytes
コンパイル時間 711 ms
コンパイル使用メモリ 92,784 KB
実行使用メモリ 50,296 KB
最終ジャッジ日時 2023-08-26 03:42:10
合計ジャッジ時間 4,079 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,828 KB
testcase_01 AC 61 ms
24,628 KB
testcase_02 AC 33 ms
16,652 KB
testcase_03 AC 146 ms
49,084 KB
testcase_04 AC 40 ms
18,392 KB
testcase_05 AC 11 ms
8,936 KB
testcase_06 AC 53 ms
22,468 KB
testcase_07 AC 96 ms
36,792 KB
testcase_08 AC 68 ms
26,644 KB
testcase_09 AC 109 ms
40,916 KB
testcase_10 AC 152 ms
50,296 KB
testcase_11 AC 46 ms
20,404 KB
testcase_12 AC 9 ms
7,012 KB
testcase_13 AC 53 ms
22,548 KB
testcase_14 AC 17 ms
9,772 KB
testcase_15 AC 60 ms
24,528 KB
testcase_16 AC 152 ms
50,204 KB
testcase_17 AC 152 ms
50,120 KB
testcase_18 AC 2 ms
5,408 KB
testcase_19 AC 2 ms
5,372 KB
testcase_20 AC 2 ms
5,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <climits>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdio>
#include <climits>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cstring>
#include <set>
#include <map>
#include <complex>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
long long MOD = 1000000007;
long long INF = 1000000000000000; //10^15
typedef long long ll;
typedef unsigned long long ull;


ll powMod(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll t = powMod(x, n/2, mod);
  t = t * t % mod;
  if (n & 1) return t * x % mod;
  return t;
}

ll a[2001000];ll sum[2001000] = {};ll c[2001000] = {};

int main(void) {
  
  int n; ll p;
  cin >> n >> p;
  
  a[1] = 0; a[2] = 1;
  for (int i = 3; i <= n; i++) {
    a[i] = ((p*a[i-1]%MOD) + a[i-2])%MOD;
  }
  
  for (int i = 1; i <= n; i++) {
    sum[i] = (sum[i - 1] + a[i])%MOD;
  }
  
  for (int i = 1; i <= n; i++) {
    c[i] = (c[i - 1] + (a[i]*sum[i]%MOD))%MOD;
  }
  cout << c[n] << endl;

  return 0;
}
0