結果

問題 No.2156 ぞい文字列
ユーザー Carpenters-CatCarpenters-Cat
提出日時 2022-12-10 01:04:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,567 bytes
コンパイル時間 2,286 ms
コンパイル使用メモリ 195,400 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-22 23:32:44
合計ジャッジ時間 2,490 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll const m = 998244353;
int main () {
    ll N;
    cin >> N;
    N --;
    ll mat[2][2];
    mat[0][0] = 0;
    mat[0][1] = mat[1][1] = mat[1][0] = 1;
    ll ret[2][2];
    for (int i = 0; i < 2; i ++) {
        for (int j = 0; j < 2; j ++) {
            ret[i][j] = (i == j);
        }
    }
    while (N) {
        if (N & 1) {
            ll mat2[2][2];
            for (int i = 0; i < 4; i ++) {
                mat2[i >> 1][i & 1] = 0;
            }
            for (int i = 0; i < 2; i ++) {
                for (int j = 0; j < 2; j ++) {
                    for (int k = 0; k < 2; k ++) {
                        mat2[i][j] += ret[i][k] * mat[k][j];
                    }
                    mat2[i][j] %= m;
                }
            }
            for (int i = 0; i < 4; i ++) {
                ret[i >> 1][i & 1] = mat2[i >> 1][i & 1];
            }
        }
        N >>= 1;
        ll mat2[2][2];
        for (int i = 0; i < 4; i ++) {
            mat2[i >> 1][i & 1] = 0;
        }
        for (int i = 0; i < 2; i ++) {
            for (int j = 0; j < 2; j ++) {
                for (int k = 0; k < 2; k ++) {
                    mat2[i][j] += mat[i][k] * mat[k][j];
                }
                mat2[i][j] %= m;
            }
        }
        for (int i = 0; i < 4; i ++) {
            mat[i >> 1][i & 1] = mat2[i >> 1][i & 1];
        }
    }
    // return 0;
    ll ans = ret[0][0] + ret[0][1] * 2;
    ans %= m;
    ans += m - 1;
    ans %= m;
    cout << ans << endl;
}
0