結果

問題 No.978 Fibonacci Convolution Easy
ユーザー 👑 zeronosu77108zeronosu77108
提出日時 2020-01-31 23:24:27
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 2,370 bytes
コンパイル時間 1,044 ms
コンパイル使用メモリ 140,868 KB
実行使用メモリ 34,432 KB
最終ジャッジ日時 2024-05-07 20:22:07
合計ジャッジ時間 2,118 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 16 ms
15,232 KB
testcase_02 AC 9 ms
9,328 KB
testcase_03 AC 31 ms
33,152 KB
testcase_04 AC 10 ms
10,732 KB
testcase_05 AC 4 ms
5,376 KB
testcase_06 AC 14 ms
13,568 KB
testcase_07 AC 21 ms
22,604 KB
testcase_08 AC 15 ms
16,640 KB
testcase_09 AC 23 ms
25,472 KB
testcase_10 AC 31 ms
34,432 KB
testcase_11 AC 11 ms
12,020 KB
testcase_12 AC 4 ms
5,376 KB
testcase_13 AC 15 ms
13,440 KB
testcase_14 AC 5 ms
6,144 KB
testcase_15 AC 14 ms
14,848 KB
testcase_16 AC 33 ms
34,432 KB
testcase_17 AC 31 ms
34,392 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;
const int MOD = 1000000007;
struct mint {
    long long x;
    explicit mint(const long long x=0) : x(x%MOD) {}

    mint& operator+=(const mint a) { if ( (x+=a.x) >= MOD) x-=MOD; return *this; }
    mint& operator-=(const mint a) { if ( (x+= MOD-a.x) >= MOD) x-= MOD; return *this; }
    mint& operator*=(const mint a) { (x*=a.x) %= MOD; return *this; }
    mint& operator/=(const mint a) { return (*this) *= a.inv();}
    mint operator+(const mint a) const { mint res(*this); return res+=a; }
    mint operator-(const mint a) const { mint res(*this); return res-=a; }
    mint operator*(const mint a) const { mint res(*this); return res*=a; }
    mint operator/(const mint a) const {mint res(*this); return res/=a;}
    mint inv() const { return pow(MOD-2);}
    friend ostream& operator<<(ostream &os, const mint a) noexcept { return os << a.x; }
    constexpr bool operator == (const mint& r) const noexcept { return this->x == r.x; }
    constexpr bool operator != (const mint& r) const noexcept { return this->x != r.x; }
    mint pow(long long t) const {
        if (!t) return mint(1);
        mint a = pow(t>>1);
        a*=a;
        if(t&1) a*= *this;
        return a;
    }
};

vector<mint> _fibo;

mint fibo(int64 n, mint p) {
    if (n <= 1) return mint(0);
    if (_fibo[n] != mint(0)) return _fibo[n];
    mint res = (p * fibo(n-1, p)) + fibo(n-2, p);
    return _fibo[n] = res;
}

int main() {
    int64 n,p;
    cin >> n >> p;
    mint ans(0);
    _fibo = vector<mint> (n+10);
    for (int i=0; i<n; i++) {
        _fibo[i] = mint(0);
    }
    _fibo[0] = mint(0); _fibo[1] = mint(0); _fibo[2] = mint(1);

    mint pm(p);
    vector<mint> wa(n+1);
    mint sum(0);
    for (int i=1; i<=n; i++) {
        mint f = fibo(i, pm);
        sum += f;
        ans += f * sum;
    }
    cout << ans << endl;
}
0