結果

問題 No.2156 ぞい文字列
ユーザー _yurimoir_yurimoir
提出日時 2022-12-09 22:11:13
言語 C++23(draft)
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,185 bytes
コンパイル時間 3,669 ms
コンパイル使用メモリ 282,836 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-22 22:19:51
合計ジャッジ時間 4,436 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

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