結果

問題 No.978 Fibonacci Convolution Easy
ユーザー hogepagefoobarhogepagefoobar
提出日時 2020-02-02 17:20:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 728 bytes
コンパイル時間 1,628 ms
コンパイル使用メモリ 169,712 KB
実行使用メモリ 34,640 KB
最終ジャッジ日時 2023-10-19 01:20:18
合計ジャッジ時間 2,774 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 18 ms
15,452 KB
testcase_02 AC 11 ms
9,584 KB
testcase_03 AC 37 ms
33,388 KB
testcase_04 AC 12 ms
10,836 KB
testcase_05 AC 5 ms
4,900 KB
testcase_06 AC 16 ms
13,936 KB
testcase_07 AC 26 ms
22,640 KB
testcase_08 AC 20 ms
16,772 KB
testcase_09 AC 29 ms
25,672 KB
testcase_10 AC 39 ms
34,640 KB
testcase_11 AC 14 ms
12,156 KB
testcase_12 AC 4 ms
4,636 KB
testcase_13 AC 16 ms
13,672 KB
testcase_14 AC 7 ms
6,220 KB
testcase_15 AC 17 ms
15,188 KB
testcase_16 AC 39 ms
34,640 KB
testcase_17 AC 38 ms
34,404 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++)
using namespace std;
typedef long long ll;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

#define M (1000000007)

int main(int argc, char** argv) {
    int n, p;
    cin >> n >> p;
    vector<ll> a(n + 1);
    vector<ll> cum(n + 1);

    a[1] = 0;
    a[2] = 1;
    cum[1] = a[1];
    cum[2] = a[1] + a[2];
    for (int i = 3; i <= n; i++) {
        a[i] = (a[i - 2] + ((p * a[i - 1]) % M)) % M;
        cum[i] = (cum[i - 1] + a[i]) % M;
    }

    ll sigma = 0;
    for (int i = 1; i <= n; i++) {
        sigma += ((a[i] * cum[i]) % M) % M;
    }

    cout << sigma % M << endl;
    return 0;
};
0