結果

問題 No.978 Fibonacci Convolution Easy
ユーザー ytftytft
提出日時 2021-04-17 13:50:33
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 18 ms / 2,000 ms
コード長 479 bytes
コンパイル時間 1,288 ms
コンパイル使用メモリ 165,416 KB
実行使用メモリ 18,792 KB
最終ジャッジ日時 2023-09-16 22:39:09
合計ジャッジ時間 2,298 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 8 ms
9,236 KB
testcase_02 AC 5 ms
6,044 KB
testcase_03 AC 17 ms
18,168 KB
testcase_04 AC 7 ms
6,972 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 7 ms
8,296 KB
testcase_07 AC 12 ms
12,904 KB
testcase_08 AC 9 ms
9,668 KB
testcase_09 AC 14 ms
14,016 KB
testcase_10 AC 18 ms
18,696 KB
testcase_11 AC 7 ms
7,368 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 7 ms
8,412 KB
testcase_14 AC 4 ms
4,404 KB
testcase_15 AC 8 ms
8,936 KB
testcase_16 AC 18 ms
18,792 KB
testcase_17 AC 18 ms
18,576 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
    long long N,p;
    cin>>N>>p;
    if(N==1){
        cout<<0<<endl;
        return 0;
    }
    long long MOD=1000000007;
    long long temp=0;
    vector<long long> a(N);
    long long ans=1,sum=1;
    a[1]=1;
    for(int i=2;i<N;++i){
        a[i]=(a[i-1]*p+a[i-2])%MOD;
        sum=(sum+a[i])%MOD;
        ans=(ans+a[i]*a[i])%MOD;
    }
    ans=(ans+sum*sum)%MOD;
    ans=(ans*500000004)%MOD;
    cout<<ans<<endl;
}
0