結果

問題 No.978 Fibonacci Convolution Easy
ユーザー firiexpfiriexp
提出日時 2020-01-31 21:38:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 36 ms / 2,000 ms
コード長 2,110 bytes
コンパイル時間 2,795 ms
コンパイル使用メモリ 94,868 KB
実行使用メモリ 10,788 KB
最終ジャッジ日時 2023-07-25 08:57:26
合計ジャッジ時間 2,974 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 16 ms
6,020 KB
testcase_02 AC 9 ms
4,736 KB
testcase_03 AC 34 ms
10,532 KB
testcase_04 AC 11 ms
4,844 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 14 ms
5,792 KB
testcase_07 AC 24 ms
8,008 KB
testcase_08 AC 17 ms
6,344 KB
testcase_09 AC 27 ms
8,760 KB
testcase_10 AC 35 ms
10,788 KB
testcase_11 AC 12 ms
5,104 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 14 ms
5,788 KB
testcase_14 AC 5 ms
4,380 KB
testcase_15 AC 15 ms
5,796 KB
testcase_16 AC 36 ms
10,744 KB
testcase_17 AC 35 ms
10,744 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>
#include <limits>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template<u32 M = 1000000007>
struct modint{
    u32 val;
    modint(): val(0){}
    template<typename T>
    modint(T t){t %= (T)M; if(t < 0) t += (T)M; val = t;}

    modint pow(ll k) const {
        modint res(1), x(val);
        while(k){
            if(k&1) res *= x;
            x *= x;
            k >>= 1;
        }
        return res;
    }
    template<typename T>
    modint& operator=(T t){t %= (T)M; if(t < 0) t += (T)M; val = t; return *this;}
    modint inv() const {return pow(M-2);}
    modint& operator+=(modint a){val += a.val; if(val >= M) val -= M; return *this;}
    modint& operator-=(modint a){if(val < a.val) val += M-a.val; else val -= a.val; return *this;}
    modint& operator*=(modint a){val = (u64)val*a.val%M; return *this;}
    modint& operator/=(modint a){return (*this) *= a.inv();}
    modint operator+(modint a) const {return modint(val) +=a;}
    modint operator-(modint a) const {return modint(val) -=a;}
    modint operator*(modint a) const {return modint(val) *=a;}
    modint operator/(modint a) const {return modint(val) /=a;}
    modint operator-(){return modint(M-val);}
    bool operator==(const modint a) const {return val == a.val;}
    bool operator!=(const modint a) const {return val != a.val;}
    bool operator<(const modint a) const {return val < a.val;}
};
using mint = modint<MOD>;

int main() {
    int n, p;
    cin >> n >> p;
    vector<mint> v(n);
    v[0] = 0; v[1] = 1;
    for (int i = 2; i < n; ++i) {
        v[i] = mint(p)*v[i-1]+v[i-2];
    }
    auto x = accumulate(v.begin(),v.end(), mint(0));
    mint y;
    for (int i = 0; i < n; ++i) {
        y += v[i]*v[i];
    }
    cout << ((x*x-y)*mint(500000004)+y).val << "\n";
    return 0;
}
0