結果

問題 No.978 Fibonacci Convolution Easy
ユーザー rodearodea
提出日時 2021-01-05 16:53:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 92 ms / 2,000 ms
コード長 1,694 bytes
コンパイル時間 1,325 ms
コンパイル使用メモリ 111,276 KB
実行使用メモリ 18,896 KB
最終ジャッジ日時 2024-04-23 20:45:03
合計ジャッジ時間 2,568 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,812 KB
testcase_01 AC 35 ms
9,444 KB
testcase_02 AC 18 ms
6,940 KB
testcase_03 AC 80 ms
18,288 KB
testcase_04 AC 23 ms
6,960 KB
testcase_05 AC 6 ms
5,376 KB
testcase_06 AC 31 ms
8,448 KB
testcase_07 AC 56 ms
12,928 KB
testcase_08 AC 38 ms
9,888 KB
testcase_09 AC 62 ms
14,444 KB
testcase_10 AC 86 ms
18,816 KB
testcase_11 AC 25 ms
7,792 KB
testcase_12 AC 6 ms
5,376 KB
testcase_13 AC 31 ms
8,244 KB
testcase_14 AC 10 ms
5,376 KB
testcase_15 AC 35 ms
9,100 KB
testcase_16 AC 90 ms
18,884 KB
testcase_17 AC 92 ms
18,896 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 #

#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

#define all(a) (a).begin(), (a).end()

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

ll modpow(ll a, ll b){
    if(b == 0) return 1;
    else if(b % 2 == 0){
        ll d = modpow(a, b / 2) % MOD;
        return (d * d) % MOD;
    }
    else{
        return (a * modpow(a, b - 1)) % MOD;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

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

    ll asum = accumulate(all(a), 0LL) % MOD;

    ll ans = 0;
    for(int i=2; i<=n; i++){
        ans += a[i] * a[i] % MOD;
        ans %= MOD;
    }

    for(int i=2; i<=n; i++){
        ans += a[i] * asum % MOD;
        ans %= MOD;
    }

    cout << ans * modpow(2, MOD - 2) % MOD << endl;

    return 0;
}
0