結果

問題 No.978 Fibonacci Convolution Easy
ユーザー utouto97
提出日時 2020-02-06 22:09:40
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 40 ms / 2,000 ms
コード長 824 bytes
コンパイル時間 1,327 ms
コンパイル使用メモリ 161,344 KB
実行使用メモリ 18,844 KB
最終ジャッジ日時 2024-09-25 06:55:29
合計ジャッジ時間 2,346 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define rep(i, l, r) for (int i = (int)(l); i < (int)(r); i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)x.size())
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

/*
 */

using vi = vector<int>;
using vvi = vector<vi>;
using P = pair<int, int>;

const int mod = 1e9+7;

signed main() {
  int n, p;
  cin >> n >> p;

  vi a(n + 1);
  a[1] = 0;
  a[2] = 1;

  rep(i, 3, n + 1) {
    a[i] = (p*a[i-1]%mod + a[i-2])%mod;
  }

  int sum = 0, ans = 0;
  for(int i = n; i >= 1; i--){
    sum = (sum + a[i])%mod;
    ans = (ans + a[i]*sum%mod)%mod;
  }

  cout << ans << endl;

  return 0;
}
0