結果

問題 No.2874 Gunegune Tree
ユーザー shobonvip
提出日時 2024-09-06 23:07:11
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 74 ms / 2,000 ms
コード長 1,757 bytes
コンパイル時間 4,168 ms
コンパイル使用メモリ 254,140 KB
最終ジャッジ日時 2025-02-24 04:53:00
ジャッジサーバーID
(参考情報)
judge5 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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;
}

int main(){
	int n; cin >> n;
	// 確率, 現在の期待値
	vector dp1(n+1, vector<mint>(5));
	vector dp2(n+1, vector<mint>(5));

	vector<mint> inv(10);
	rep(i,1,10){
		inv[i] = mint(i).inv();
	}

	dp1[1][0] = inv[5];
	dp1[1][1] = inv[5];
	dp1[1][2] = inv[5];
	dp1[1][3] = inv[5];
	dp1[1][4] = inv[5];
	dp2[1][1] = inv[5];
	dp2[1][2] = inv[5];
	dp2[1][3] = inv[5];
	rep(i,1,n){
		rep(j,0,5){
			int v = 0;
			rep(k,0,5){
				if (abs(j-k) <= 1){
					v += 1;
				}
			}
			rep(k,0,5){
				if (abs(j-k) <= 1){
					if (1<=k && k<=3){
						dp2[i+1][k] += dp1[i][j] * inv[v];
					}
					dp2[i+1][k] += dp2[i][j] * inv[v];
					dp1[i+1][k] += dp1[i][j] * inv[v];
				}
			}
		}
	}
	cout << sum(dp2[n]).val() << '\n';
}

0