結果

問題 No.978 Fibonacci Convolution Easy
ユーザー kk
提出日時 2020-09-08 21:40:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 44 ms / 2,000 ms
コード長 1,013 bytes
コンパイル時間 2,411 ms
コンパイル使用メモリ 200,908 KB
実行使用メモリ 34,352 KB
最終ジャッジ日時 2023-08-20 08:08:08
合計ジャッジ時間 4,085 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 20 ms
15,208 KB
testcase_02 AC 12 ms
9,208 KB
testcase_03 AC 43 ms
33,060 KB
testcase_04 AC 13 ms
10,444 KB
testcase_05 AC 5 ms
4,532 KB
testcase_06 AC 17 ms
13,556 KB
testcase_07 AC 29 ms
22,288 KB
testcase_08 AC 21 ms
16,552 KB
testcase_09 AC 32 ms
25,376 KB
testcase_10 AC 43 ms
34,352 KB
testcase_11 AC 16 ms
11,776 KB
testcase_12 AC 4 ms
4,380 KB
testcase_13 AC 18 ms
13,312 KB
testcase_14 AC 7 ms
5,908 KB
testcase_15 AC 20 ms
14,872 KB
testcase_16 AC 44 ms
34,196 KB
testcase_17 AC 44 ms
34,000 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++)
#define ALL(x) (x).begin(), (x).end()

const double PI = acos(-1);
const long long MOD = 1e9 + 7;

long long modpow(long long x, long long p, long long mod) {
  long long ret = 1;
  while (p) {
    if (p & 1)
      ret = ret * x % mod;
    x = x * x % mod;
    p >>= 1;
  }
  return ret;
}

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

  int n, p;
  cin >> n >> p;
  vector<long long> f(n), g(n);

  f[1] = g[1] = 1;
  for (int i = 2; i < n; i++) {
    f[i] = (p * f[i-1] % MOD + f[i-2]) % MOD;
    g[i] = f[i] * f[i] % MOD;
  }

  long long fsum = 0, gsum = 0;
  for (int i = 0; i < n; i++) {
    fsum = (fsum + f[i]) % MOD;
    gsum = (gsum + g[i]) % MOD;
  }

  long long ret = fsum * fsum % MOD;
  ret = (ret - gsum + MOD) % MOD;
  ret = ret * modpow(2, MOD-2, MOD) % MOD;
  ret = (ret + gsum) % MOD;

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