結果

問題 No.3044 よくあるカエルさん
ユーザー shobonvip
提出日時 2025-02-28 22:41:32
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,174 bytes
コンパイル時間 4,650 ms
コンパイル使用メモリ 259,820 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2025-02-28 22:41:38
合計ジャッジ時間 5,396 ms
ジャッジサーバーID
(参考情報)
judge1 / judge6
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

/**
	author:  shobonvip
	created: 2025.02.28 22:39:39
**/

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

//* ATCODER
#include<atcoder/all>
using namespace atcoder;
typedef modint998244353 mint;
//*/

/* BOOST MULTIPRECISION
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
//*/

typedef long long ll;

#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)
#define all(v) v.begin(), v.end()

template <typename T> bool chmin(T &a, const T &b) {
	if (a <= b) return false;
	a = b;
	return true;
}

template <typename T> bool chmax(T &a, const T &b) {
	if (a >= b) return false;
	a = b;
	return true;
}

template <typename T> T max(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]);
	return ret;
}

template <typename T> T min(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]);
	return ret;
}

template <typename T> T sum(vector<T> &a){
	T ret = 0;
	for (int i=0; i<(int)a.size(); i++) ret += a[i];
	return ret;
}

mint bostan_mori(ll n, vector<mint> p, vector<mint> q){
	assert(p.size() < q.size());
	while (n > 0){
		vector<mint> qi((int)q.size());
		for (int i=0; i<(int)q.size(); i++){
			if (i%2==0) qi[i] = q[i];
			else qi[i] = -q[i];
		}
		vector<mint> qq = convolution<mint>(q, qi);
		q.resize(((int)qq.size()+1)/2);
		for (int i=0; i<((int)qq.size()+1)/2; i++){
			q[i] = qq[2*i];
		}
		vector<mint> pp = convolution<mint>(p, qi);
		if (n%2==0){
			p.resize(((int)pp.size()+1)/2);
			for (int i=0; i<((int)pp.size()+1)/2; i++){
				p[i] = pp[2*i];
			}
		}else{
			p.resize((int)pp.size()/2);
			for (int i=0; i<(int)pp.size()/2; i++){
				p[i] = pp[2*i+1];
			}
		}
		n/=2;
	}
	return p[0]*q[0].inv();
}


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	

	ll n; cin >> n;
	int t; cin >> t;
	int k, l; cin >> k >> l;
	mint inv6 = mint(6).inv();
	vector<mint> f(t+1);
	f[0] += 1;
	rep(i,1,k) {
		f[1] -= inv6;
	}
	rep(i,k,l){
		f[2] -= inv6;
	}
	rep(i,l,7){
		f[t] -= inv6;
	}

	n--;
	cout << bostan_mori(n,{1},f).val() << endl;
}

0