結果

問題 No.978 Fibonacci Convolution Easy
ユーザー risujirohrisujiroh
提出日時 2020-01-31 21:43:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 1,197 bytes
コンパイル時間 1,629 ms
コンパイル使用メモリ 168,472 KB
実行使用メモリ 10,948 KB
最終ジャッジ日時 2023-10-19 01:00:06
合計ジャッジ時間 2,667 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 12 ms
6,400 KB
testcase_02 AC 7 ms
4,816 KB
testcase_03 AC 25 ms
10,752 KB
testcase_04 AC 8 ms
5,080 KB
testcase_05 AC 3 ms
4,348 KB
testcase_06 AC 11 ms
5,872 KB
testcase_07 AC 18 ms
8,180 KB
testcase_08 AC 13 ms
6,664 KB
testcase_09 AC 18 ms
8,904 KB
testcase_10 AC 25 ms
10,948 KB
testcase_11 AC 9 ms
5,344 KB
testcase_12 AC 3 ms
4,348 KB
testcase_13 AC 11 ms
5,872 KB
testcase_14 AC 5 ms
4,348 KB
testcase_15 AC 12 ms
6,136 KB
testcase_16 AC 26 ms
10,948 KB
testcase_17 AC 25 ms
10,948 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 <bits/stdc++.h>
using namespace std;

template <unsigned Mod> struct Modular {
  using M = Modular;
  unsigned v;
  Modular(long long a = 0) : v((a %= Mod) < 0 ? a + Mod : a) {}
  M operator-() const { return M() -= *this; }
  M& operator+=(M r) { if ((v += r.v) >= Mod) v -= Mod; return *this; }
  M& operator-=(M r) { if ((v += Mod - r.v) >= Mod) v -= Mod; return *this; }
  M& operator*=(M r) { v = (uint64_t)v * r.v % Mod; return *this; }
  M& operator/=(M r) { return *this *= power(r, Mod - 2); }
  friend M operator+(M l, M r) { return l += r; }
  friend M operator-(M l, M r) { return l -= r; }
  friend M operator*(M l, M r) { return l *= r; }
  friend M operator/(M l, M r) { return l /= r; }
  friend bool operator==(M l, M r) { return l.v == r.v; }
};

constexpr long long mod = 1e9 + 7;
using Mint = Modular<mod>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, p;
  cin >> n >> p;
  vector<Mint> a(n);
  for (int i = 0; i < n; ++i) {
    if (i < 2) {
      a[i] = i;
    } else {
      a[i] = p * a[i - 1] + a[i - 2];
    }
  }
  Mint res, sum;
  for (int i = 0; i < n; ++i) {
    sum += a[i];
    res += sum * a[i];
  }
  cout << res.v << '\n';
}
0