結果

問題 No.978 Fibonacci Convolution Easy
ユーザー Konton7Konton7
提出日時 2020-03-05 05:33:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 1,318 bytes
コンパイル時間 1,975 ms
コンパイル使用メモリ 197,316 KB
実行使用メモリ 34,688 KB
最終ジャッジ日時 2024-04-22 02:01:21
合計ジャッジ時間 3,175 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 14 ms
15,360 KB
testcase_02 AC 9 ms
9,472 KB
testcase_03 AC 31 ms
33,152 KB
testcase_04 AC 10 ms
10,832 KB
testcase_05 AC 4 ms
5,376 KB
testcase_06 AC 13 ms
13,824 KB
testcase_07 AC 20 ms
22,560 KB
testcase_08 AC 15 ms
16,712 KB
testcase_09 AC 22 ms
25,500 KB
testcase_10 AC 31 ms
34,404 KB
testcase_11 AC 12 ms
12,120 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 13 ms
13,696 KB
testcase_14 AC 5 ms
6,400 KB
testcase_15 AC 13 ms
14,976 KB
testcase_16 AC 32 ms
34,688 KB
testcase_17 AC 32 ms
34,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
using PII = std::pair<int, int>;
using PLL = std::pair<ll, ll>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define allpt(v) (v).begin(), (v).end()
#define allpt_r(v) (v).rbegin(), (v).rend()


const int mod = 1e9 + 7;
const string wsp = " ";
const string tb = "\t";
const string rt = "\n";

template <typename T>
void show1dvec(vector<T> v)
{
    int n = v.size() - 1;
    rep(i, n) cout << v[i] << wsp;
    cout << v[n] << rt;
    return;
}

template <typename T>
void show2dvec(vector<vector<T>> v)
{
    int n = v.size();
    rep(i, n) show1dvec(v[i]);
}

int main()
{

#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif

    ll n, p, s = 0, ans = 0;
    cin >> n >> p;
    vector<ll> f(n), sf(n);
    f[0] = 0, f[1] = 1;
    rep(i, n - 2)
    {
        f[i + 2] = (p * f[i + 1] + f[i]) % mod;
    }
    

    rep(i, n)
    {
        s += f[i];
        s %= mod;
        sf[i] = s;
        ans += (f[i] * s) % mod;
        ans %= mod;
    }

    cout << ans << endl;


    return 0;
}
0