結果

問題 No.3515 Anti EIKO
コンテスト
ユーザー tnakao0123
提出日時 2026-04-25 18:07:26
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 333 ms / 2,000 ms
コード長 3,203 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 481 ms
コンパイル使用メモリ 58,620 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-04-25 18:07:33
合計ジャッジ時間 5,947 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

/* -*- coding: utf-8 -*-
 *
 * 3515.cc:  No.3515 Anti EIKO - yukicoder
 */

#include<cstdio>
#include<algorithm>

using namespace std;

/* constant */

const int MAX_N = 25;
const int MAX_N4 = MAX_N * 4;
const int MOD = 998244353;

/* typedef */

using ll = long long;

template<const int MOD>
struct MI {
  int v;
  MI(): v() {}
  MI(int _v): v(_v % MOD) { if (v < 0) v += MOD; }
  MI(long long _v): v(_v % MOD) { if (v < 0) v += MOD; }

  explicit operator int() const { return v; }
  
  MI operator+(const MI m) const { return MI(v + m.v); }
  MI operator-(const MI m) const { return MI(v + MOD - m.v); }
  MI operator-() const { return MI(MOD - v); }
  MI operator*(const MI m) const { return MI((long long)v * m.v); }

  MI &operator+=(const MI m) { return (*this = *this + m); }
  MI &operator-=(const MI m) { return (*this = *this - m); }
  MI &operator*=(const MI m) { return (*this = *this * m); }

  bool operator==(const MI m) const { return v == m.v; }
  bool operator!=(const MI m) const { return v != m.v; }

  MI pow(ll n) const {  // a^n % MOD
    MI pm = 1, a = *this;
    while (n > 0) {
      if (n & 1) pm *= a;
      a *= a;
      n >>= 1;
    }
    return pm;
  }

  MI inv() const { return pow(MOD - 2); }
  MI operator/(const MI m) const { return *this * m.inv(); }
  MI &operator/=(const MI m) { return (*this = *this / m); }
};

using mi = MI<MOD>;
using vec = mi[MAX_N4];
using mat = vec[MAX_N4];

/* global variables */

mat ma, mb;

/* subroutines */

inline void initvec(const int n, vec a) { fill(a, a + n, 0); }

inline void initmat(const int n, mat a) {
  for (int i = 0; i < n; i++) initvec(n, a[i]);
}

inline void unitmat(const int n, mat a) {
  initmat(n, a);
  for (int i = 0; i < n; i++) a[i][i] = 1;
}

inline void copymat(const int n, const mat a, mat b) {
  for (int i = 0; i < n; i++) copy(a[i], a[i] + n, b[i]);
}

inline void mulmat(const int n, const mat a, const mat b, mat c) {
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      c[i][j] = 0;
      for (int k = 0; k < n; k++)
        c[i][j] += a[i][k] * b[k][j];
    }
}

inline void powmat(const int n, const mat a, ll b, mat c) {
  mat s, t;
  copymat(n, a, s);
  unitmat(n, c);

  while (b > 0) {
    if (b & 1) {
      mulmat(n, c, s, t);
      copymat(n, t, c);
    }

    mulmat(n, s, s, t);
    copymat(n, t, s);
    b >>= 1;
  }
}

inline void mulmatvec(const int n, const mat a, const vec b, vec c) {
  for (int i = 0; i < n; i++) {
    c[i] = 0;
    for (int j = 0; j < n; j++) c[i] += a[i][j] * b[j];
  }
}

void printmat(const int n, const mat a) {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (j) putchar(' ');
      printf("%d", a[i][j]);
    }
    putchar('\n');
  }
}

/* main */

int main() {
  int n;
  ll k;
  scanf("%d%lld", &n, &k);

  int n4 = n * 4;
  initmat(n4, ma);
  for (int i = 0; i < n4; i++)
    for (int j = 0; j < n4; j++) {
      if (i == 0)
	ma[i][j] = ! (j & 3) ? 4 : 3;
      else if (i == 1)
	ma[i][j] = (j > 0 && ! (j & 3)) ? 0 : 1;
      else if (i == j + 1)
	ma[i][j] = 1;
    }
  //printmat(n4, ma);
  powmat(n4, ma, k - 1, mb);

  mi p = mb[n4 - 1][0] / mi(5).pow(k);
  printf("%d\n", (int)p);
  
  return 0;
}

0