結果

問題 No.2156 ぞい文字列
ユーザー _yurimoir_yurimoir
提出日時 2022-12-09 22:11:13
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,185 bytes
コンパイル時間 3,280 ms
コンパイル使用メモリ 253,808 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-14 22:09:12
合計ジャッジ時間 4,032 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=998244353;
vector<ll> mmulmatvec(vector<vector<ll>> a,vector<ll> v){
    vector<ll> ret(2,0);
    for(int i=0;i<2;i++){
        for(int j=0;j<2;j++){
            ret[i]+=a[i][j]*v[j];
            ret[i]%=mod;
        }
    }
    return ret;
}
vector<vector<ll>> mmulmat(vector<vector<ll>> a,vector<vector<ll>> b){
    vector<vector<ll>> ret(2,vector<ll>(2,0));
    for(int i=0;i<2;i++){
        for(int j=0;j<2;j++){
            for(int k=0;k<2;k++){
                ret[i][j]+=a[i][k]*b[k][j];
                ret[i][j]%=mod;
            }
        }
    }
    return ret;
}
vector<vector<ll>> mpowmat(vector<vector<ll>> a,ll b){
    vector<vector<ll>> ret={{1,0},{0,1}},apow=a;
    while(b){
        if(b&1)ret=mmulmat(ret,apow);
        apow=mmulmat(apow,apow);
        b=b>>1;
    }
    return ret;
}
int main(){
    ll n;
    cin>>n;
    // zoi * i , zo * (n - 2 * i)
    // i : 1 ~ n/2
    //S i:1~n/2 (n-i)Ci
    vector<vector<ll>> b={
        {1,1},{1,0}
    };
    vector<ll> init={1,0};
    vector<ll> mat=mmulmatvec(mpowmat(b,n-1),init);
    ll ans=(mat[0]+mat[1])%mod;
    cout<<ans-1<<endl;
}
0