結果

問題 No.978 Fibonacci Convolution Easy
ユーザー merom686merom686
提出日時 2020-01-31 22:23:50
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 616 bytes
コンパイル時間 743 ms
コンパイル使用メモリ 75,964 KB
実行使用メモリ 11,068 KB
最終ジャッジ日時 2023-10-19 01:03:52
合計ジャッジ時間 1,679 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 11 ms
6,520 KB
testcase_02 AC 7 ms
4,936 KB
testcase_03 AC 22 ms
10,872 KB
testcase_04 AC 7 ms
5,200 KB
testcase_05 AC 3 ms
4,348 KB
testcase_06 AC 10 ms
5,992 KB
testcase_07 AC 16 ms
8,300 KB
testcase_08 AC 12 ms
6,784 KB
testcase_09 AC 17 ms
9,024 KB
testcase_10 AC 22 ms
11,068 KB
testcase_11 AC 9 ms
5,464 KB
testcase_12 AC 3 ms
4,348 KB
testcase_13 AC 10 ms
5,992 KB
testcase_14 AC 4 ms
4,348 KB
testcase_15 AC 11 ms
6,256 KB
testcase_16 AC 22 ms
11,068 KB
testcase_17 AC 21 ms
11,068 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 <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
using ll = long long;

constexpr int P = 1000000007;

int main() {
    int n, p;
    cin >> n >> p;

    vector<int> a(n);
    a[0] = 0;
    a[1] = 1;

    ll s = a[0] + a[1];
    for (int i = 2; i < n; i++) {
        s += a[i] = ((ll)p * a[i - 1] + a[i - 2]) % P;
    }
    s %= P;

    ll r = 0;
    for (int i = 0; i < n; i++) {
        r += a[i] * s % P;
        s -= a[i];
        if (s < 0) s += P;
    }
    r %= P;

    cout << r << endl;

    return 0;
}
0