結果

問題 No.980 Fibonacci Convolution Hard
ユーザー snow39snow39
提出日時 2020-02-01 00:16:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 430 ms / 2,000 ms
コード長 905 bytes
コンパイル時間 939 ms
コンパイル使用メモリ 94,140 KB
実行使用メモリ 34,620 KB
最終ジャッジ日時 2023-10-17 14:23:35
合計ジャッジ時間 11,370 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 426 ms
34,620 KB
testcase_01 AC 426 ms
34,620 KB
testcase_02 AC 430 ms
34,620 KB
testcase_03 AC 427 ms
34,620 KB
testcase_04 AC 426 ms
34,620 KB
testcase_05 AC 428 ms
34,620 KB
testcase_06 AC 427 ms
34,620 KB
testcase_07 AC 428 ms
34,620 KB
testcase_08 AC 427 ms
34,620 KB
testcase_09 AC 426 ms
34,620 KB
testcase_10 AC 427 ms
34,620 KB
testcase_11 AC 425 ms
34,620 KB
testcase_12 AC 427 ms
34,620 KB
testcase_13 AC 429 ms
34,620 KB
testcase_14 AC 428 ms
34,620 KB
testcase_15 AC 427 ms
34,620 KB
testcase_16 AC 402 ms
34,620 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

void add(ll &a,ll b){
  a=(a+b)%MOD;
}

int main(){
  int N=2000010;
  ll P;
  cin>>P;

  vector<ll> A(N,0);
  A[0]=0;
  A[1]=1;
  for(int i=2;i<N;i++) A[i]=(P*A[i-1]%MOD+A[i-2])%MOD;

  vector<ll> ans(N,0);
  ans[0]=0;ans[1]=0;ans[2]=0;ans[3]=1;
  for(int i=4;i<=N;i++){
    ll res=0;
    add(res,2*P%MOD*ans[i-1]%MOD);
    add(res,MOD-(P*P%MOD-2+MOD)%MOD*ans[i-2]%MOD);
    add(res,MOD-2*P%MOD*ans[i-3]%MOD);
    add(res,MOD-ans[i-4]);
    add(ans[i],res);
  }

  int Q;
  cin>>Q;
  rep(q,Q){
    int val;cin>>val;
    val--;
    cout<<ans[val]<<endl;
  }

  return 0;
}
0