結果

問題 No.2668 Trees on Graph Paper
ユーザー 沙耶花沙耶花
提出日時 2024-03-08 22:13:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,107 ms / 3,000 ms
コード長 994 bytes
コンパイル時間 4,301 ms
コンパイル使用メモリ 263,616 KB
実行使用メモリ 425,300 KB
最終ジャッジ日時 2024-03-08 22:13:58
合計ジャッジ時間 33,116 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 260 ms
425,300 KB
testcase_01 AC 217 ms
425,300 KB
testcase_02 AC 212 ms
425,300 KB
testcase_03 AC 381 ms
425,300 KB
testcase_04 AC 195 ms
425,300 KB
testcase_05 AC 197 ms
425,300 KB
testcase_06 AC 221 ms
425,300 KB
testcase_07 AC 195 ms
425,300 KB
testcase_08 AC 218 ms
425,300 KB
testcase_09 AC 196 ms
425,300 KB
testcase_10 AC 194 ms
425,300 KB
testcase_11 AC 192 ms
425,300 KB
testcase_12 AC 195 ms
425,300 KB
testcase_13 AC 194 ms
425,300 KB
testcase_14 AC 1,316 ms
425,300 KB
testcase_15 AC 1,901 ms
425,300 KB
testcase_16 AC 1,060 ms
425,300 KB
testcase_17 AC 275 ms
425,300 KB
testcase_18 AC 1,814 ms
425,300 KB
testcase_19 AC 1,603 ms
425,300 KB
testcase_20 AC 1,731 ms
425,300 KB
testcase_21 AC 1,636 ms
425,300 KB
testcase_22 AC 1,670 ms
425,300 KB
testcase_23 AC 1,132 ms
425,300 KB
testcase_24 AC 2,057 ms
425,300 KB
testcase_25 AC 2,107 ms
425,300 KB
testcase_26 AC 2,067 ms
425,300 KB
testcase_27 AC 2,061 ms
425,300 KB
testcase_28 AC 193 ms
425,300 KB
testcase_29 AC 193 ms
425,300 KB
testcase_30 AC 193 ms
425,300 KB
testcase_31 AC 193 ms
425,300 KB
testcase_32 AC 192 ms
425,300 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 1000000000000000001

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int n,m;
	cin>>n>>m;
	mint::set_mod(m);
	
	mint dp[12000000][3][3];
	rep(i,12000000){
		rep(j,3){
			rep(k,3){
				dp[i][j][k] = 0;
			}
		}
	}
	dp[1][2][2] = 1;
	for(int i=2;i<=n*2;i++){
		rep(j,3){
			rep(k,3){
				rep(l,3){
					if((i-1+k) > (i+l))continue;
					mint nv = dp[i-1][j][k];
					if(l!=0 && k!=1 && j!=2){
						nv *= i-2;
					}
					dp[i][k][l] += nv;
				}
			}
		}
	}
	mint ans = 1;
	for(int i=3;i<=n*2-1;i+=2){
		mint sum = 0;
		rep(j,3){
			rep(k,3){
				if(k==2)continue;
				mint v = dp[i-1][j][k];
				sum += v;
			}
		}
		ans *= sum;
		
	}
//	cout<<ans.val()<<endl;
	rep(i,n*2-1){
		
		//cout<<i+1<<endl;
		ans *= i+1;
	}
	
	cout<<ans.val()<<endl;
	
	return 0;
}
0