結果

問題 No.978 Fibonacci Convolution Easy
ユーザー takumi152takumi152
提出日時 2020-01-31 22:34:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 925 bytes
コンパイル時間 903 ms
コンパイル使用メモリ 99,112 KB
実行使用メモリ 18,840 KB
最終ジャッジ日時 2023-10-19 01:04:26
合計ジャッジ時間 1,982 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 13 ms
9,344 KB
testcase_02 AC 9 ms
6,312 KB
testcase_03 AC 27 ms
18,048 KB
testcase_04 AC 10 ms
7,036 KB
testcase_05 AC 3 ms
4,348 KB
testcase_06 AC 12 ms
8,356 KB
testcase_07 AC 19 ms
12,904 KB
testcase_08 AC 14 ms
9,872 KB
testcase_09 AC 22 ms
14,224 KB
testcase_10 AC 29 ms
18,840 KB
testcase_11 AC 11 ms
7,564 KB
testcase_12 AC 3 ms
4,348 KB
testcase_13 AC 12 ms
8,356 KB
testcase_14 AC 5 ms
4,728 KB
testcase_15 AC 12 ms
9,080 KB
testcase_16 AC 29 ms
18,840 KB
testcase_17 AC 29 ms
18,840 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 <iomanip>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <cstdlib>
#include <queue>
#include <unordered_map>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;

const ll mod = 1000000007;

ll modinv(ll x, ll m = mod) {
  ll b = m;
  ll u = 1;
  ll v = 0;
  ll tmp;
  while (b) {
    ll t = x / b;
    x -= t * b;
    tmp = x;
    x = b;
    b = tmp;
    u -= t * v;
    tmp = u;
    u = v;
    v = tmp;
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll n, p;
  cin >> n >> p;

  vector<ll> a(max(2LL, n));
  a[0] = 0;
  a[1] = 1;
  for (int i = 2; i < n; i++) {
    a[i] = (p * a[i-1] + a[i-2]) % mod;
  }

  ll ans = 0;
  ll s = 0;
  for (int i = 0; i < n; i++) {
    s = (s + a[i]) % mod;
    ans = (ans + s * a[i]) % mod;
  }

  cout << ans << endl;

  return 0;
}
0