結果

問題 No.980 Fibonacci Convolution Hard
ユーザー kyort0nkyort0n
提出日時 2020-01-31 22:21:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 331 ms / 2,000 ms
コード長 1,042 bytes
コンパイル時間 1,593 ms
コンパイル使用メモリ 166,572 KB
実行使用メモリ 34,800 KB
最終ジャッジ日時 2023-10-17 13:35:18
合計ジャッジ時間 9,956 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 328 ms
34,800 KB
testcase_01 AC 325 ms
34,800 KB
testcase_02 AC 325 ms
34,800 KB
testcase_03 AC 328 ms
34,800 KB
testcase_04 AC 327 ms
34,800 KB
testcase_05 AC 324 ms
34,800 KB
testcase_06 AC 328 ms
34,800 KB
testcase_07 AC 326 ms
34,800 KB
testcase_08 AC 331 ms
34,800 KB
testcase_09 AC 328 ms
34,800 KB
testcase_10 AC 324 ms
34,800 KB
testcase_11 AC 325 ms
34,800 KB
testcase_12 AC 329 ms
34,800 KB
testcase_13 AC 326 ms
34,800 KB
testcase_14 AC 325 ms
34,800 KB
testcase_15 AC 325 ms
34,800 KB
testcase_16 AC 302 ms
34,800 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
const ll mod = 1000000007;
ll p;
ll P[2000100];
ll a[2000010];

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> p;
    a[2] = 1;
    for(int i = 3; i <= 2e6; i++) {
        a[i] = p * a[i-1] + a[i-2];
        a[i] %= mod;
    }
    P[1] = 0;
    P[2] = 0;
    P[3] = 0;
    P[4] = 1;
    for(int i = 5; i <= 2e6; i++) {
        P[i] = P[i-1] * p + P[i-2] + a[i-2];
        P[i] %= mod;
    }
    int Q;
    cin >> Q;
    while(Q--) {
        int q;
        cin >> q;
        cout << P[q] << endl;
    }
    return 0;
}
0