結果

問題 No.2156 ぞい文字列
ユーザー hiro71687khiro71687k
提出日時 2023-08-23 07:46:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,150 bytes
コンパイル時間 5,648 ms
コンパイル使用メモリ 264,812 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-23 07:46:31
合計ジャッジ時間 6,537 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using namespace std;
using ll=long long;
using ld=long double;
ld pie=3.141592653589793;
ll mod=998244353;
ll inf=1009999999999999990;
vector<vector<ll>>mul(vector<vector<ll>>&a,vector<vector<ll>>&b){
    vector<vector<ll>>c(a.size(),vector<ll>(b[0].size(),0));
    for (ll i = 0; i < a.size(); i++)
    {
        for (ll j = 0; j < b[0].size(); j++)
        {
            for (ll k = 0; k < a[0].size(); k++)
            {
                c[i][j]+=(a[i][k]*b[k][j])%mod;
                c[i][j]%=mod;
            }
        }
    }
    return c;
}
vector<vector<ll>>matpow(vector<vector<ll>>a,ll n){
    vector<vector<ll>>b(a.size(),vector<ll>(a.size(),0));
    for (ll i = 0; i < a.size(); i++)
    {
        b[i][i]=1;
    }
    while (n>0)
    {
        if (n%2)
        {
            b=mul(a,b);
            n-=1;
        }else{
            a=mul(a,a);
            n/=2;
        }
    }
    return b;
}
int main(){
    ll n;
    cin >> n;
    vector<vector<ll>>a={{1,0,0},{0,1,1},{1,1,0}};
    vector<vector<ll>>b=matpow(a,n-1);
    cout << (b[1][0]+b[2][0])%mod << endl;
}
0