結果

問題 No.2857 Div Array
ユーザー square1001square1001
提出日時 2024-07-15 10:00:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 1,430 bytes
コンパイル時間 1,446 ms
コンパイル使用メモリ 106,808 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-15 10:00:30
合計ジャッジ時間 3,618 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,948 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 4 ms
6,944 KB
testcase_11 AC 45 ms
6,944 KB
testcase_12 AC 11 ms
6,944 KB
testcase_13 AC 5 ms
6,944 KB
testcase_14 AC 42 ms
6,944 KB
testcase_15 AC 6 ms
6,940 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 37 ms
6,944 KB
testcase_18 AC 33 ms
6,940 KB
testcase_19 AC 19 ms
6,944 KB
testcase_20 AC 58 ms
6,944 KB
testcase_21 AC 56 ms
6,940 KB
testcase_22 AC 56 ms
6,940 KB
testcase_23 AC 56 ms
6,944 KB
testcase_24 AC 2 ms
6,944 KB
testcase_25 AC 2 ms
6,944 KB
testcase_26 AC 2 ms
6,944 KB
testcase_27 AC 2 ms
6,944 KB
testcase_28 AC 2 ms
6,940 KB
testcase_29 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <map>
#include <cmath>
#include <vector>
#include <iostream>
using namespace std;

int main() {
	// step #1. preparation
	const int MOD = 998244353;
	auto matmul = [&](int n, vector<vector<int> > a, vector<vector<int> > b) {
		vector<vector<int> > c(n, vector<int>(n));
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				for (int k = 0; k < n; k++) {
					c[i][j] = (c[i][j] + 1LL * a[i][k] * b[k][j]) % MOD;
				}
			}
		}
		return c;
	};
	auto matpow = [&](int n, vector<vector<int> > a, int k) {
		vector<vector<int> > c(n, vector<int>(n));
		for (int i = 0; i < n; i++) {
			c[i][i] = 1;
		}
		while (k != 0) {
			if (k % 2 == 1) {
				c = matmul(n, c, a);
			}
			a = matmul(n, a, a);
			k /= 2;
		}
		return c;
	};

	// step #2. input
	int N, M, K;
	cin >> N >> M >> K;

	// step #3. calculation
	map<int, int> d;
	for (int i = 1; i <= M; i++) {
		d[M / i]++;
	}
	int Z = d.size();
	vector<int> v, c;
	for (pair<int, int> i : d) {
		v.push_back(i.first);
		c.push_back(i.second);
	}
	vector<vector<int> > mat(Z, vector<int>(Z));
	for (int i = 0; i < Z; i++) {
		for (int j = 0; j < Z; j++) {
			if (abs(v[i] - v[j]) <= K) {
				mat[i][j] = c[j];
			}
		}
	}
	vector<vector<int> > res = matpow(Z, mat, N - 1);
	int ans = 0;
	for (int i = 0; i < Z; i++) {
		for (int j = 0; j < Z; j++) {
			ans = (ans + 1LL * c[i] * res[i][j]) % MOD;
		}
	}
	
	// step #4. output
	cout << ans << endl;

	return 0;
}
0