結果

問題 No.2668 Trees on Graph Paper
ユーザー shobonvipshobonvip
提出日時 2024-03-08 23:01:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 665 ms / 3,000 ms
コード長 1,544 bytes
コンパイル時間 5,206 ms
コンパイル使用メモリ 265,872 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2024-03-08 23:01:45
合計ジャッジ時間 13,020 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 57 ms
6,548 KB
testcase_04 AC 2 ms
6,548 KB
testcase_05 AC 2 ms
6,548 KB
testcase_06 AC 2 ms
6,548 KB
testcase_07 AC 2 ms
6,548 KB
testcase_08 AC 2 ms
6,548 KB
testcase_09 AC 2 ms
6,548 KB
testcase_10 AC 2 ms
6,548 KB
testcase_11 AC 2 ms
6,548 KB
testcase_12 AC 2 ms
6,548 KB
testcase_13 AC 2 ms
6,548 KB
testcase_14 AC 385 ms
6,548 KB
testcase_15 AC 583 ms
6,548 KB
testcase_16 AC 293 ms
6,548 KB
testcase_17 AC 31 ms
6,548 KB
testcase_18 AC 557 ms
6,548 KB
testcase_19 AC 477 ms
6,548 KB
testcase_20 AC 526 ms
6,548 KB
testcase_21 AC 498 ms
6,548 KB
testcase_22 AC 506 ms
6,548 KB
testcase_23 AC 322 ms
6,548 KB
testcase_24 AC 639 ms
6,548 KB
testcase_25 AC 645 ms
6,548 KB
testcase_26 AC 637 ms
6,548 KB
testcase_27 AC 665 ms
6,548 KB
testcase_28 AC 2 ms
6,548 KB
testcase_29 AC 2 ms
6,548 KB
testcase_30 AC 2 ms
6,548 KB
testcase_31 AC 2 ms
6,548 KB
testcase_32 AC 2 ms
6,548 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;
}

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

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

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

0