結果

問題 No.3243 Multiplication 8 1
ユーザー areik
提出日時 2025-08-22 22:47:59
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 123 ms / 2,000 ms
コード長 2,412 bytes
コンパイル時間 3,975 ms
コンパイル使用メモリ 257,780 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-08-22 22:48:04
合計ジャッジ時間 4,821 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "atcoder/fenwicktree.hpp"
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;

using isize = size_t;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
using f64 = long double;
using p2 = pair<i64, i64>;
using el = tuple<i64, i64, i64>;
using mint = atcoder::modint998244353;

void _main();
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  _main();
}

i64 pow(i64 x, i64 n) {
  i64 res = 1;
  i64 t = x;
  while (n > 0) {
    if (n & 1) {
      res = res * t;
    }
    t = t * t;
    n >>= 1;
  }
  return res;
}
i64 pow(i64 x, i64 n, i64 m) {
  i64 res = 1;
  i64 t = x % m;
  while (n > 0) {
    if (n & 1) {
      res = res * t % m;
    }
    t = t * t % m;
    n >>= 1;
  }
  return res;
}

vector<vector<mint>> mul(vector<vector<mint>> &a, vector<vector<mint>> &b) {
  vector<vector<mint>> res(a.size(), vector<mint>(b[0].size(), 0));
  assert(a[0].size() == b.size());
  for (i64 i = 0; i < a.size(); i++) {
    for (i64 j = 0; j < b[0].size(); j++) {
      for (i64 k = 0; k < b.size(); k++) {
        res[i][j] += a[i][k] * b[k][j];
      }
    }
  }
  return res;
}
vector<vector<mint>> pow(vector<vector<mint>> &a, i64 n) {
  assert(a.size() == a[0].size());
  vector<vector<mint>> res(a.size(), vector<mint>(a[0].size(), 0));
  vector<vector<mint>> t = a;
  for (i64 i = 0; i < a.size(); i++) res[i][i] = 1;
  while (n > 0) {
    if (n & 1) {
      vector<vector<mint>> nres = mul(res, t);
      swap(res, nres);
    }
    vector<vector<mint>> nt = mul(t, t);
    swap(nt, t);
    n >>= 1;
  }
  return res;
}
void _main() {
  i64 ttt;
  cin >> ttt;
  for (;ttt--;) {
    i64 n;
    cin >> n;
    vector<vector<mint>> a(8, vector<mint>(8, 0));
    for (i64 i = 0; i < 8; i++) {
      if (i == 3) {
        continue;
      }
      if (i == 7) {
        a[7][0] = a[7][7] = 1;
        continue;
      }
      for (i64 j = 0; j < 8; j++) {
        if ((i % 4) == (j % 4) || (i % 4) + 1 == (j % 4)) {
          if (j == 3) {
            a[i][0]++;
          } else {
            a[i][j]++;
          }
        }
      }
    }
    a = pow(a, n);
    // for (i64 i = 0; i < 8; i++) {
    //   for (i64 j = 0; j < 8; j++) {
    //     cout << a[i][j].val() << " ";
    //   }
    //   cout << "\n";
    // }
    cout << (a[0][0] - mint(2).pow(n - 1)).val() << "\n";
  }
}
0