結果

問題 No.840 ほむほむほむら
ユーザー norikamenorikame
提出日時 2023-02-11 03:44:40
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 175 ms / 4,000 ms
コード長 1,818 bytes
コンパイル時間 6,319 ms
コンパイル使用メモリ 312,112 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-22 03:28:53
合計ジャッジ時間 8,678 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 4 ms
4,376 KB
testcase_03 AC 18 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 8 ms
4,380 KB
testcase_08 AC 38 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 12 ms
4,376 KB
testcase_13 AC 111 ms
4,376 KB
testcase_14 AC 15 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 27 ms
4,376 KB
testcase_18 AC 144 ms
4,380 KB
testcase_19 AC 175 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 3 ms
4,380 KB
testcase_23 AC 168 ms
4,380 KB
testcase_24 AC 4 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 4 ms
4,376 KB
testcase_27 AC 167 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// 

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

using ll = long long;

#define rep(i, n) for (int i=0; i<(int)(n); ++(i))
#define rep3(i, m, n) for (int i=(m); (i)<(int)(n); ++(i))
#define repr(i, n) for (int i=(int)(n)-1; (i)>=0; --(i))
#define rep3r(i, m, n) for (int i=(int)(n)-1; (i)>=(int)(m); --(i))
#define all(x) (x).begin(), (x).end()

using mint = modint998244353;

template<typename T>
struct Matrix {
    int h, w;
    vector<vector<T>> d;
    Matrix() {}
    Matrix(int h, int w, T val=0) : h(h), w(w), d(h, vector<T>(w, val)) {}
    Matrix& unit() {
        assert(h == w);
        rep(i, h) d[i][i] = 1;
        return *this;
    }
    const vector<T>& operator[](int i) const { return d[i]; }
    vector<T>& operator[](int i) { return d[i]; }
    Matrix operator*(const Matrix& a) const {
        assert(w == a.h);
        Matrix r(h, a.w);
        rep(i, h) rep(k, w) rep(j, a.w) {
            r[i][j] += d[i][k] * a[k][j];
        }
        return r;
    }
    Matrix pow(long long t) const {
        assert(h == w);
        if (!t) return Matrix(h, h).unit();
        if (t == 1) return *this;
        Matrix r = pow(t>>1);
        r = r * r;
        if (t&1) r = r * (*this);
        return r;
    }
};

int main() {
    int n, k;
    cin >> n >> k;
    Matrix<mint> r(k*k*k, k*k*k);
    rep(i1, k) rep(i2, k) rep(i3, k) {
        int j1 = (i1 + 1) % k, j2 = i2, j3 = i3;
        r[i1*k*k+i2*k+i3][j1*k*k+j2*k+j3] += 1;
        j1 = i1, j2 = (i2 + i1) % k, j3 = i3;
        r[i1*k*k+i2*k+i3][j1*k*k+j2*k+j3] += 1;
        j1 = i1, j2 = i2, j3 = (i3 + i2) % k;
        r[i1*k*k+i2*k+i3][j1*k*k+j2*k+j3] += 1;
    }
    r = r.pow(n);
    mint res = 0;
    for (int i=0; i<k*k*k; i+=k) res += r[i][0];
    cout << res.val() << endl;
    return 0;
}
0