結果

問題 No.978 Fibonacci Convolution Easy
ユーザー bachoppibachoppi
提出日時 2020-01-31 22:39:54
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 44 ms / 2,000 ms
コード長 926 bytes
コンパイル時間 2,008 ms
コンパイル使用メモリ 96,184 KB
実行使用メモリ 34,772 KB
最終ジャッジ日時 2023-10-19 01:05:00
合計ジャッジ時間 2,802 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 21 ms
15,684 KB
testcase_02 AC 13 ms
9,660 KB
testcase_03 AC 43 ms
33,488 KB
testcase_04 AC 14 ms
11,140 KB
testcase_05 AC 5 ms
5,120 KB
testcase_06 AC 18 ms
14,020 KB
testcase_07 AC 29 ms
22,924 KB
testcase_08 AC 21 ms
16,904 KB
testcase_09 AC 33 ms
25,804 KB
testcase_10 AC 43 ms
34,708 KB
testcase_11 AC 15 ms
12,360 KB
testcase_12 AC 4 ms
4,936 KB
testcase_13 AC 17 ms
13,840 KB
testcase_14 AC 7 ms
6,416 KB
testcase_15 AC 19 ms
15,320 KB
testcase_16 AC 43 ms
34,772 KB
testcase_17 AC 44 ms
34,672 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<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
#define PI 3.141592653589793

int main(){
  ll N, p; cin >> N >> p; ll a[N], cum[N+1]; 
  a[0]=0; a[1]=1; cum[0]=0, cum[1]=0, cum[2]=1;
  rep(i, N-2){
    int Q; Q = a[i+1]*p%mod;
    a[i+2] = a[i] + Q; a[i+2]%=mod;
    cum[i+3] = cum[i+2] + a[i+2]; cum[i+3]%=mod;
  }
  ll ans = 0;
  rep(i, N){
    ll K = cum[N] - cum[i];
    if(K<0) K+=mod; K%=mod;
    ll A = a[i]*K; A%=mod;
    ans+=A; ans%=mod;
  }
  cout << ans << endl;
}
0