結果

問題 No.2156 ぞい文字列
ユーザー ymmtr(せるたわーしーぷ!)ymmtr(せるたわーしーぷ!)
提出日時 2022-12-09 22:46:30
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,611 bytes
コンパイル時間 1,709 ms
コンパイル使用メモリ 174,304 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-05 00:46:24
合計ジャッジ時間 2,644 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

//D
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
using ll = long long;
#define ALL(a)  (a).begin(),(a).end()
using v_vll = vector<vector<ll>>;
const ll mod=998244353;
v_vll matrix_mult(v_vll a,v_vll b){
    v_vll ret(a.size(),vector<ll> (b[0].size()));
    for(ll i=0;i<a.size();i++){
        for(ll j=0;j<b[0].size();j++){
            for(ll k=0;k<b.size();k++){
                ret[i][j]+=(a[i][k]*b[k][j])%mod;
            }
        }
    }
    return ret;
}
v_vll matrix_pow(v_vll a,ll n){
    v_vll ret(a.size(),vector<ll>(a.size()));
    for(ll i=0;i<a.size();i++){
        ret[i][i]=1;
    }
    while(n>0){
        if(n&1){
            ret=matrix_mult(a,ret);
        }
        a=matrix_mult(a,a);
        n>>=1;
    }
    return ret;
}
ll f(ll n){
    v_vll a={
        {1,1},
        {1,0}
    };
    a=matrix_pow(a,n);
    ll nth,nm2th;
    nth=a[1][0];
    return nth;
}
int main(){
    //一旦愚直DP書いてみるか
    ll n;cin>>n;
    
    //cout<<nm2th<<endl;
    cout<<(f(n)%mod+f(n-1)%mod-1)%mod<<endl;
    //くり返し二乗法
    //vector<vector<ll>> dp(n+10,vector<ll> (2));
    //dp[1][0]=1;
    /*for(ll i=2;i<=n;i++){
        dp[i][0]=(dp[i-1][0]+dp[i-1][1])%998244353;
        dp[i][1]=dp[i-1][0]%998244353;
    }*/
    /*cout<<"fast"<<endl;
    cout<<f(n)%mod<<" "<<f(n-1)%mod<<endl;
    cout<<"slow"<<endl;
    cout<<dp[n][0]<<" "<<dp[n][1]<<endl;*/
    /*for(ll i=1;i<=n;i++){
        cout<<dp[i][0]<<" ";
    }cout<<endl;
    for(ll i=0;i<=n;i++){
        cout<<dp[i][1]<<" ";
    }cout<<endl;*/
    //cout<<(dp[n][0]+dp[n][1]-1)%998244353<<endl;
}
0