結果

問題 No.2668 Trees on Graph Paper
ユーザー askr58askr58
提出日時 2024-03-08 23:50:48
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 911 ms / 3,000 ms
コード長 481 bytes
コンパイル時間 3,135 ms
コンパイル使用メモリ 250,400 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-08 23:51:02
合計ジャッジ時間 14,060 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 79 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 4 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 530 ms
6,676 KB
testcase_15 AC 835 ms
6,676 KB
testcase_16 AC 409 ms
6,676 KB
testcase_17 AC 42 ms
6,676 KB
testcase_18 AC 792 ms
6,676 KB
testcase_19 AC 662 ms
6,676 KB
testcase_20 AC 740 ms
6,676 KB
testcase_21 AC 713 ms
6,676 KB
testcase_22 AC 701 ms
6,676 KB
testcase_23 AC 443 ms
6,676 KB
testcase_24 AC 888 ms
6,676 KB
testcase_25 AC 909 ms
6,676 KB
testcase_26 AC 911 ms
6,676 KB
testcase_27 AC 884 ms
6,676 KB
testcase_28 AC 2 ms
6,676 KB
testcase_29 AC 2 ms
6,676 KB
testcase_30 AC 2 ms
6,676 KB
testcase_31 AC 2 ms
6,676 KB
testcase_32 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
	ll n,m;
	cin>>n>>m;
	vector<vector<ll>> dp(2,vector<ll>(3));
	dp[0][0]=1%m;
	dp[0][1]=2%m;
	dp[0][2]=3%m;
	ll ans=1;
	for(ll i=4;i<2*n;i++){
		dp[1][0]=(dp[0][1]+dp[0][0])%m;
		dp[1][1]=(dp[0][0]*(i-2)%m+dp[0][1]+dp[0][2])%m;
		dp[1][2]=(dp[0][0]*((i-2)*(i-1)%m)+dp[0][1]*(i-1)%m+dp[0][2])%m;
		if(i&1)ans=ans*dp[1][0]%m;
		swap(dp[0],dp[1]);
	}
	for(ll i=1;i<2*n;i++)ans=ans*i%m;
	cout<<ans<<endl;

}
0