結果

問題 No.840 ほむほむほむら
ユーザー norikamenorikame
提出日時 2022-07-09 02:47:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 663 ms / 4,000 ms
コード長 1,322 bytes
コンパイル時間 2,852 ms
コンパイル使用メモリ 212,388 KB
実行使用メモリ 12,324 KB
最終ジャッジ日時 2023-08-28 12:32:39
合計ジャッジ時間 8,358 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 7 ms
4,376 KB
testcase_02 AC 73 ms
5,944 KB
testcase_03 AC 536 ms
12,184 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 8 ms
4,380 KB
testcase_07 AC 76 ms
5,936 KB
testcase_08 AC 549 ms
12,000 KB
testcase_09 AC 7 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 8 ms
4,380 KB
testcase_12 AC 77 ms
5,840 KB
testcase_13 AC 608 ms
12,324 KB
testcase_14 AC 80 ms
5,596 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 8 ms
4,376 KB
testcase_17 AC 92 ms
5,764 KB
testcase_18 AC 573 ms
12,236 KB
testcase_19 AC 641 ms
12,256 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 7 ms
4,380 KB
testcase_22 AC 73 ms
5,908 KB
testcase_23 AC 624 ms
12,112 KB
testcase_24 AC 9 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 74 ms
5,568 KB
testcase_27 AC 663 ms
11,952 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// 

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

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()

const ll mod = 998244353LL;

struct Matrix {
	int sz;
	vector<vector<ll>> x;
	Matrix(int sz=0) : sz(sz), x(sz, vector<ll>(sz)) {}
};

Matrix multiply(Matrix A, Matrix B) {
	Matrix C(A.sz);
	rep(i, A.sz) rep(j, B.sz) {
		rep(k, C.sz) C.x[i][j] = (C.x[i][j] + A.x[i][k] * B.x[k][j]) % mod;
	}
	return C;
}

Matrix matpow(Matrix A, ll t) {
	vector<Matrix> E(64, Matrix(A.sz));
	E[0] = A;
	rep(i, 63) E[i+1] = multiply(E[i], E[i]);
	Matrix res(A.sz);
	rep(i, res.sz) res.x[i][i] = 1;
	repr(i, 63) if (t & (1LL<<i)) res = multiply(res, E[i]);
	return res;
}

int main() {
	int n, k;
	cin >> n >> k;
	Matrix mat(k*k*k);
	rep(i, k*k*k) {
		int v1 = i%k, v2 = i/k%k, v3 = i/k/k%k;
		int nv1 = (v1+1) % k, nv2 = (v2+v1) % k, nv3 = (v3+v2) % k;
		mat.x[nv1+v2*k+v3*k*k][i]++;
		mat.x[v1+nv2*k+v3*k*k][i]++;
		mat.x[v1+v2*k+nv3*k*k][i]++;
	}
	auto amat = matpow(mat, n);
	ll res = 0;
	rep(i, k*k*k) if (i/k/k == 0) res = (res + amat.x[i][0]) % mod;
	cout << res << endl;
	return 0;
}
0