結果

問題 No.3044 よくあるカエルさん
ユーザー kwm_t
提出日時 2025-03-02 15:01:29
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 67 ms / 2,000 ms
コード長 1,962 bytes
コンパイル時間 6,252 ms
コンパイル使用メモリ 332,932 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2025-03-02 15:01:37
合計ジャッジ時間 7,757 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
using mint = modint998244353;
const int mod = 998244353;
//const int INF = 1e9;
//const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r) - 1;i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define P pair<int,int>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
template<typename T>
std::vector<vector<T>> matrixMul(const std::vector<std::vector<T>>&A, const std::vector<std::vector<T>>&B) {
	std::vector<vector<T>> C(A.size(), std::vector<T>(B[0].size()));
	for (int i = 0; i < (int)A.size(); ++i) {
		for (int k = 0; k < (int)A[0].size(); ++k) {
			for (int j = 0; j < (int)B[0].size(); ++j) {
				C[i][j] += A[i][k] * B[k][j];
			}
		}
	}
	return C;
}
template<typename T>
std::vector<std::vector<T>> matrixPow(long long n, std::vector<std::vector<T>> mat) {
	int size = (int)mat.size();
	vector<vector<mint>> mret(size, vector<mint>(size));
	for (int i = 0; i < size; ++i) {
		mret[i][i] = 1;
	}
	while (n > 0) {
		if (1 & n) mret = matrixMul(mat, mret);
		mat = matrixMul(mat, mat);
		n >>= 1;
	}
	return mret;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n, t; cin >> n >> t;
	int k, l; cin >> k >> l;
	mint inv6 = mint(6).inv();
	vector mul(t, vector<mint>(t));
	mul[0][0] = (k - 1) * inv6;
	mul[0][1] = (l - k) * inv6;
	mul[0][t - 1] = (7 - l) * inv6;
	rep2(i, 1, t)mul[i][i - 1] = 1;
	mul = matrixPow(n - 1, mul);
	mint ans = mul[0][0];
	cout << ans.val() << endl;
	return 0;
}
0