結果

問題 No.978 Fibonacci Convolution Easy
ユーザー yoshig0731yoshig0731
提出日時 2020-02-07 00:32:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 52 ms / 2,000 ms
コード長 1,005 bytes
コンパイル時間 3,233 ms
コンパイル使用メモリ 170,528 KB
実行使用メモリ 34,632 KB
最終ジャッジ日時 2023-10-25 22:51:52
合計ジャッジ時間 3,147 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,348 KB
testcase_01 AC 22 ms
15,444 KB
testcase_02 AC 13 ms
9,576 KB
testcase_03 AC 50 ms
33,380 KB
testcase_04 AC 15 ms
10,828 KB
testcase_05 AC 5 ms
4,892 KB
testcase_06 AC 20 ms
13,928 KB
testcase_07 AC 34 ms
22,632 KB
testcase_08 AC 25 ms
16,764 KB
testcase_09 AC 38 ms
25,664 KB
testcase_10 AC 52 ms
34,632 KB
testcase_11 AC 18 ms
12,148 KB
testcase_12 AC 4 ms
4,628 KB
testcase_13 AC 19 ms
13,664 KB
testcase_14 AC 8 ms
6,212 KB
testcase_15 AC 22 ms
15,180 KB
testcase_16 AC 51 ms
34,632 KB
testcase_17 AC 51 ms
34,396 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 <bits/stdc++.h>

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(obj) obj.begin(), obj.end()
#define fcout cout << setprecision(10)

template <class T>
inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

const int iINF = 1e9;
const long long llINF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;

int main() { 
    int N;
    long long p;
    cin >> N >> p;
    vector<long long> a(N + 1, 0), b;
    a[0] = 0;
    a[1] = 0;
    a[2] = 1;
    for (int i = 3; i < N + 1; i++) {
        a[i] = (p * a[i - 1]) % MOD + a[i - 2] % MOD;
        a[i] %= MOD;
    }

    b = a;

    REP(i, N) {
        b[i + 1] += b[i];
        b[i + 1] %= MOD;
    }

    long long ans = 0;
    for (int i = 1; i < N + 1; i++) {
        ans += a[i] * (b[i]);
        ans %= MOD;
    }

    cout << ans << endl;


    return 0; 
}
0