結果

問題 No.978 Fibonacci Convolution Easy
ユーザー pekempeypekempey
提出日時 2020-02-14 10:43:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 36 ms / 2,000 ms
コード長 540 bytes
コンパイル時間 655 ms
コンパイル使用メモリ 73,724 KB
実行使用メモリ 18,944 KB
最終ジャッジ日時 2024-04-16 00:10:38
合計ジャッジ時間 1,815 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 15 ms
9,344 KB
testcase_02 AC 9 ms
6,272 KB
testcase_03 AC 34 ms
18,176 KB
testcase_04 AC 10 ms
7,168 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 13 ms
8,448 KB
testcase_07 AC 23 ms
12,928 KB
testcase_08 AC 17 ms
9,856 KB
testcase_09 AC 27 ms
14,336 KB
testcase_10 AC 36 ms
18,944 KB
testcase_11 AC 12 ms
7,680 KB
testcase_12 AC 4 ms
5,376 KB
testcase_13 AC 13 ms
8,448 KB
testcase_14 AC 5 ms
5,376 KB
testcase_15 AC 15 ms
9,216 KB
testcase_16 AC 35 ms
18,944 KB
testcase_17 AC 35 ms
18,816 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;

using ll = long long;
constexpr ll MOD = 1000000007;

int main() {
    ll N, p;
    cin >> N >> p;
    vector<ll> a(N + 1);
    a[1] = 0;
    a[2] = 1;
    for (int n = 3; n <= N; n++) {
        a[n] = p * a[n - 1] + a[n - 2];
        a[n] %= MOD;
    }
    ll ans = 0;
    ll tmp = 0;
    for (int i = 1; i <= N; i++) {
        tmp += a[i];
        tmp %= MOD;
        ans += a[i] * tmp;
        ans %= MOD;
    }
    cout << ans << endl;
}
0