結果

問題 No.980 Fibonacci Convolution Hard
ユーザー koi_kotyakoi_kotya
提出日時 2020-02-01 01:32:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 385 ms / 2,000 ms
コード長 885 bytes
コンパイル時間 1,582 ms
コンパイル使用メモリ 168,792 KB
実行使用メモリ 34,624 KB
最終ジャッジ日時 2023-10-17 18:38:31
合計ジャッジ時間 11,051 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 384 ms
34,624 KB
testcase_01 AC 382 ms
34,624 KB
testcase_02 AC 385 ms
34,624 KB
testcase_03 AC 380 ms
34,624 KB
testcase_04 AC 383 ms
34,624 KB
testcase_05 AC 381 ms
34,624 KB
testcase_06 AC 376 ms
34,624 KB
testcase_07 AC 381 ms
34,624 KB
testcase_08 AC 378 ms
34,624 KB
testcase_09 AC 382 ms
34,624 KB
testcase_10 AC 383 ms
34,624 KB
testcase_11 AC 380 ms
34,624 KB
testcase_12 AC 385 ms
34,624 KB
testcase_13 AC 383 ms
34,624 KB
testcase_14 AC 381 ms
34,624 KB
testcase_15 AC 381 ms
34,624 KB
testcase_16 AC 355 ms
34,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;
ll const mod = 1e9+7;

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int main() {
    ll p;
    int q;
    cin >> p;
    vector<ll> ans(2000010),a(2000010);
    a[1] = 0;
    a[2] = 1;
    for (int i = 3;i < 2000010;++i) a[i] = (p*a[i-1]+a[i-2])%mod;
    ans[1] = 0;
    ans[2] = 0;
    for (int i = 3;i < 2000010;++i) ans[i] = (p*ans[i-1]+ans[i-2]+a[i-2])%mod;
    cin >> q;
    for (int i = 0;i < q;++i) {
        int t;
        cin >> t;
        cout << ans[t] << "\n";
    }
}
0