結果

問題 No.840 ほむほむほむら
ユーザー QCFiumQCFium
提出日時 2019-06-27 12:56:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 155 ms / 4,000 ms
コード長 1,191 bytes
コンパイル時間 1,667 ms
コンパイル使用メモリ 167,972 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-09 23:26:37
合計ジャッジ時間 4,777 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 5 ms
4,376 KB
testcase_03 AC 22 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 7 ms
4,380 KB
testcase_08 AC 38 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 13 ms
4,384 KB
testcase_13 AC 93 ms
4,380 KB
testcase_14 AC 14 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 21 ms
4,380 KB
testcase_18 AC 154 ms
4,384 KB
testcase_19 AC 155 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 154 ms
4,380 KB
testcase_24 AC 3 ms
4,376 KB
testcase_25 AC 2 ms
4,384 KB
testcase_26 AC 3 ms
4,384 KB
testcase_27 AC 130 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define MOD 998244353

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
int main() {
	int n = ri();
	int k = ri();
	int kk = k * k;
	int kkk = k * k * k;
	int a[kkk][kkk];
	memset(a, 0, sizeof(a));
	for (int i = 0; i < k*k*k; i++) {
		int x = i / kk;
		int y = i / k % k;
		int z = i % k;
		a[i][x * kk + y * k + (z + 1) % k]++;
		a[i][x * kk + (y + z) % k * k + z]++;
		a[i][(x + y) % k * kk + y * k + z]++;
	}
	std::vector<int> res(kkk, 0);
	std::vector<int> tmp(kkk);
	res[0] = 1;
	while (n) {
		if (n & 1) {
			tmp.assign(kkk, 0);
			for (int i = 0; i < kkk; i++)
				for (int j = 0; j < kkk; j++) {
					tmp[j] += (int64_t) res[i] * a[i][j] % MOD;
					if (tmp[j] >= MOD) tmp[j] -= MOD;
				}
			std::swap(tmp, res);
		}
		int b[kkk][kkk];
		memset(b, 0, sizeof(b));
		for (int i = 0; i < kkk; i++) {
			for (int j = 0; j < kkk; j++) {
				for (int l = 0; l < kkk; l++) {
					b[i][j] += (int64_t) a[i][l] * a[l][j] % MOD;
					if (b[i][j] >= MOD) b[i][j] -= MOD;
				}
			}
		}
		memcpy(a, b, sizeof(a));
		n /= 2;
	}
	int ans = 0;
	for (int i = 0; i < kk; i++) {
		ans += res[i];
		if (ans >= MOD) ans -= MOD;
	}
	std::cout << ans << std::endl;
	return 0;
}
0