結果

問題 No.978 Fibonacci Convolution Easy
ユーザー RubikunRubikun
提出日時 2020-01-31 21:43:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 894 bytes
コンパイル時間 1,592 ms
コンパイル使用メモリ 170,164 KB
実行使用メモリ 18,932 KB
最終ジャッジ日時 2023-10-19 00:59:25
合計ジャッジ時間 2,647 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 13 ms
9,436 KB
testcase_02 AC 8 ms
6,404 KB
testcase_03 AC 27 ms
18,140 KB
testcase_04 AC 9 ms
7,128 KB
testcase_05 AC 4 ms
4,348 KB
testcase_06 AC 12 ms
8,448 KB
testcase_07 AC 18 ms
12,996 KB
testcase_08 AC 15 ms
9,964 KB
testcase_09 AC 22 ms
14,316 KB
testcase_10 AC 29 ms
18,932 KB
testcase_11 AC 10 ms
7,656 KB
testcase_12 AC 3 ms
4,348 KB
testcase_13 AC 13 ms
8,448 KB
testcase_14 AC 5 ms
4,820 KB
testcase_15 AC 12 ms
9,172 KB
testcase_16 AC 28 ms
18,932 KB
testcase_17 AC 28 ms
18,932 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 <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=200005,INF=1<<30;

ll rui(ll a,ll b){
    ll ans=1;
    while(b>0){
        if(b&1) ans=ans*a%mod;
        a=a*a%mod;
        b/=2;
    }
    return ans;
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;ll P;cin>>N>>P;
    vector<ll> S(N);
    S[0]=0;
    S[1]=1;
    for(int i=2;i<N;i++){
        S[i]=(S[i-1]*P+S[i-2])%mod;
    }
    
    ll sum=0,cen=0;
    
    for(int i=0;i<N;i++){
        sum+=S[i];
        cen+=S[i]*S[i];
        
        sum%=mod;
        cen%=mod;
    }
    
    //cout<<sum<<" "<<cen<<endl;
    
    sum=sum*sum;
    sum+=mod-cen;
    sum%=mod;
    
    //cout<<sum<<endl;
    
    cout<<(sum*rui(2,mod-2)+cen)%mod<<endl;
    
}

0