結果

問題 No.2156 ぞい文字列
ユーザー SSRSSSRS
提出日時 2022-12-09 21:45:36
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,095 bytes
コンパイル時間 1,386 ms
コンパイル使用メモリ 165,284 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-22 21:34:39
合計ジャッジ時間 1,980 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
array<array<long long, 3>, 3> matmul(array<array<long long, 3>, 3> A, array<array<long long, 3>, 3> B){
  array<array<long long, 3>, 3> C;
  for (int i = 0; i < 3; i++){
    for (int j = 0; j < 3; j++){
      C[i][j] = 0;
    }
  }
  for (int i = 0; i < 3; i++){
    for (int j = 0; j < 3; j++){
      for (int k = 0; k < 3; k++){
        C[i][k] += A[i][j] * B[j][k];
        C[i][k] %= MOD;
      }
    }
  }
  return C;
}
array<array<long long, 3>, 3> matexp(array<array<long long, 3>, 3> A, long long N){
  array<array<long long, 3>, 3> ans;
  for (int i = 0; i < 3; i++){
    for (int j = 0; j < 3; j++){
      if (i == j){
        ans[i][j] = 1;
      } else {
        ans[i][j] = 0;
      }
    }
  }
  while (N > 0){
    if (N % 2 == 1){
      ans = matmul(ans, A);
    }
    A = matmul(A, A);
    N /= 2;
  }
  return ans;
}
int main(){
  long long N;
  cin >> N;
  array<array<long long, 3>, 3> A = {{{1, 0, 1}, {0, 1, 1}, {0, 1, 0}}};
  A = matexp(A, N - 1);
  cout << (A[0][1] + A[0][2]) % MOD << endl;
}
0