結果

問題 No.978 Fibonacci Convolution Easy
ユーザー first_vilfirst_vil
提出日時 2020-01-31 21:51:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 2,433 bytes
コンパイル時間 1,670 ms
コンパイル使用メモリ 172,392 KB
実行使用メモリ 34,480 KB
最終ジャッジ日時 2023-10-19 01:00:16
合計ジャッジ時間 2,814 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,348 KB
testcase_01 AC 19 ms
15,292 KB
testcase_02 AC 11 ms
9,424 KB
testcase_03 AC 42 ms
33,228 KB
testcase_04 AC 13 ms
10,676 KB
testcase_05 AC 5 ms
4,740 KB
testcase_06 AC 17 ms
13,776 KB
testcase_07 AC 28 ms
22,480 KB
testcase_08 AC 21 ms
16,612 KB
testcase_09 AC 31 ms
25,512 KB
testcase_10 AC 43 ms
34,480 KB
testcase_11 AC 15 ms
11,996 KB
testcase_12 AC 4 ms
4,476 KB
testcase_13 AC 16 ms
13,512 KB
testcase_14 AC 7 ms
6,060 KB
testcase_15 AC 18 ms
15,028 KB
testcase_16 AC 43 ms
34,480 KB
testcase_17 AC 42 ms
34,244 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>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10; //1e-9?
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int n;
ll p;
VL memo;
ll f(int i) {
    if (i == 1)return 0;
    if (i == 2)return 1;
    if (memo[i] != -1)return memo[i];
    return memo[i] = ((p * f(i - 1) % mod) + f(i - 2)) % mod;
}

int main() {
    init();

    cin >> n >> p;
    memo.resize(n + 1, -1);
    ll ans = 0;
    VL a(n + 1);
    eFOR(i, 1, n) {
        a[i] = (a[i - 1] + f(i)) % mod;
        (ans += a[i] * f(i)) %= mod;
    }
    cout << ans << "\n";
}
0