結果

問題 No.2156 ぞい文字列
ユーザー ripityripity
提出日時 2022-12-09 22:29:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 913 bytes
コンパイル時間 3,222 ms
コンパイル使用メモリ 223,240 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-27 04:20:46
合計ジャッジ時間 3,888 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
constexpr long long MOD = 998244353;
vector<vector<long long>> prod(vector<vector<long long>>& X, vector<vector<long long>>& Y) {
    vector<vector<long long>> Z = {{0, 0}, {0, 0}};
    for( int i = 0; i < 2; i++ ) {
        for( int j = 0; j < 2; j++ ) {
            for( int k = 0; k < 2; k++ ) {
                Z[i][j] += X[i][k]*Y[k][j]%MOD;
                Z[i][j] %= MOD;
            }
        }
    }
    return Z;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long N;
    cin >> N;
    N--;
    vector<vector<long long>> A = {{1, 1}, {1, 0}}, B = {{1, 0}, {0, 1}};
    while( N > 0 ) {
        if( N&1 ) {
            B = prod(A, B);
        }
        A = prod(A, A);
        N >>= 1;
    }
    cout << (B[0][0]+B[1][0]-1+MOD)%MOD << endl;
}
0