結果

問題 No.2668 Trees on Graph Paper
ユーザー shobonvipshobonvip
提出日時 2024-03-08 22:58:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,721 bytes
コンパイル時間 5,590 ms
コンパイル使用メモリ 266,580 KB
実行使用メモリ 597,096 KB
最終ジャッジ日時 2024-03-08 22:58:46
合計ジャッジ時間 25,601 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 165 ms
50,352 KB
testcase_01 AC 151 ms
50,352 KB
testcase_02 AC 150 ms
50,352 KB
testcase_03 AC 260 ms
97,940 KB
testcase_04 AC 156 ms
50,352 KB
testcase_05 AC 151 ms
50,352 KB
testcase_06 AC 151 ms
50,352 KB
testcase_07 AC 165 ms
50,352 KB
testcase_08 AC 151 ms
50,352 KB
testcase_09 AC 150 ms
50,352 KB
testcase_10 AC 151 ms
50,352 KB
testcase_11 AC 177 ms
50,352 KB
testcase_12 AC 152 ms
50,352 KB
testcase_13 AC 151 ms
50,352 KB
testcase_14 AC 988 ms
377,872 KB
testcase_15 MLE -
testcase_16 AC 794 ms
302,012 KB
testcase_17 AC 209 ms
75,008 KB
testcase_18 MLE -
testcase_19 AC 1,102 ms
458,448 KB
testcase_20 AC 1,174 ms
492,644 KB
testcase_21 AC 1,148 ms
473,056 KB
testcase_22 AC 1,116 ms
481,912 KB
testcase_23 AC 758 ms
323,312 KB
testcase_24 MLE -
testcase_25 MLE -
testcase_26 MLE -
testcase_27 MLE -
testcase_28 AC 150 ms
50,352 KB
testcase_29 AC 151 ms
50,352 KB
testcase_30 AC 152 ms
50,352 KB
testcase_31 AC 150 ms
50,352 KB
testcase_32 AC 151 ms
50,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

//* ATCODER
#include<atcoder/all>
using namespace atcoder;
typedef modint 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;
}

//defmodfact
const int COMinitMAX = 12000000;
mint fact[COMinitMAX+1];

void modfact(){
	fact[0] = 1;
	for (int i=1; i<=COMinitMAX; i++){
		fact[i] = fact[i-1] * i;
	}
}

//--------


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

	int n, m; cin >> n >> m;
	mint::set_mod(m);

	modfact();
	
	vector dp(2*n + 5, vector<mint>(3));
	dp[0][0] = 1;
	rep(i,0,2*n+4){
		rep(j,0,3){
			if (j-1 >= 0){
				dp[i+1][j-1] += mint(i+1) * dp[i][j];
			}
			dp[i+1][j] += dp[i][j];
			if (j+1 < 3){
				dp[i+1][j+1] += dp[i][j];
			}
			if (j+2 < 3){
				dp[i+1][j+2] += dp[i][j];
			}
		}
	}
	
	mint ans = fact[2*n-1];
	rep(i,1,n){
		ans *= dp[2*i-1][2];
	}
	cout << ans.val() << '\n';
}

0