結果

問題 No.978 Fibonacci Convolution Easy
ユーザー set0gut1set0gut1
提出日時 2020-01-31 21:40:17
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 830 bytes
コンパイル時間 887 ms
コンパイル使用メモリ 86,324 KB
実行使用メモリ 34,480 KB
最終ジャッジ日時 2023-10-19 00:57:33
合計ジャッジ時間 1,932 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 19 ms
15,292 KB
testcase_02 AC 12 ms
9,424 KB
testcase_03 AC 41 ms
33,228 KB
testcase_04 AC 13 ms
10,676 KB
testcase_05 AC 5 ms
4,740 KB
testcase_06 AC 17 ms
13,776 KB
testcase_07 AC 28 ms
22,480 KB
testcase_08 AC 21 ms
16,612 KB
testcase_09 AC 31 ms
25,512 KB
testcase_10 AC 42 ms
34,480 KB
testcase_11 AC 15 ms
11,996 KB
testcase_12 AC 4 ms
4,476 KB
testcase_13 AC 16 ms
13,512 KB
testcase_14 AC 7 ms
6,060 KB
testcase_15 AC 18 ms
15,028 KB
testcase_16 AC 42 ms
34,480 KB
testcase_17 AC 42 ms
34,244 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 <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define MOD (1000000007l)
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)

using namespace std;

void solve() {
  ll N, P;
  cin >> N >> P;
  vector<ll> A(N);
  A[0] = 0;
  A[1] = 1;
  for (ll i = 2; i < N; i++) {
    ll tmp = P * A[i-1] + A[i-2];
    tmp %= MOD;
    A[i] = tmp;
  }
  vector<ll> B(N);
  for (ll i = 1; i < N; i++) {
    B[i] = (B[i-1] + A[i]) % MOD;
  }

  ll ans = 0;
  rep (i, N) {
    ans += B[i] * A[i];
    ans %= MOD;
  }

  cout << ans << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  cout << fixed;
  solve();
  return 0;
}
0