結果

問題 No.2135 C5
ユーザー 沙耶花沙耶花
提出日時 2023-07-11 15:28:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 314 ms / 2,000 ms
コード長 1,599 bytes
コンパイル時間 4,632 ms
コンパイル使用メモリ 268,344 KB
実行使用メモリ 6,248 KB
最終ジャッジ日時 2023-10-11 06:30:53
合計ジャッジ時間 9,507 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
5,884 KB
testcase_01 AC 8 ms
5,828 KB
testcase_02 AC 7 ms
5,892 KB
testcase_03 AC 116 ms
6,112 KB
testcase_04 AC 8 ms
6,056 KB
testcase_05 AC 7 ms
5,836 KB
testcase_06 AC 7 ms
5,880 KB
testcase_07 AC 8 ms
5,820 KB
testcase_08 AC 7 ms
5,884 KB
testcase_09 AC 7 ms
5,884 KB
testcase_10 AC 8 ms
5,908 KB
testcase_11 AC 8 ms
5,820 KB
testcase_12 AC 8 ms
5,848 KB
testcase_13 AC 7 ms
5,884 KB
testcase_14 AC 8 ms
5,940 KB
testcase_15 AC 34 ms
5,996 KB
testcase_16 AC 28 ms
6,020 KB
testcase_17 AC 126 ms
6,180 KB
testcase_18 AC 22 ms
5,900 KB
testcase_19 AC 8 ms
5,832 KB
testcase_20 AC 8 ms
5,852 KB
testcase_21 AC 8 ms
5,844 KB
testcase_22 AC 14 ms
6,092 KB
testcase_23 AC 207 ms
6,096 KB
testcase_24 AC 47 ms
5,952 KB
testcase_25 AC 7 ms
6,056 KB
testcase_26 AC 7 ms
5,876 KB
testcase_27 AC 8 ms
5,868 KB
testcase_28 AC 8 ms
5,884 KB
testcase_29 AC 242 ms
6,132 KB
testcase_30 AC 41 ms
6,056 KB
testcase_31 AC 117 ms
6,040 KB
testcase_32 AC 40 ms
6,168 KB
testcase_33 AC 8 ms
5,992 KB
testcase_34 AC 7 ms
5,812 KB
testcase_35 AC 7 ms
5,832 KB
testcase_36 AC 7 ms
6,044 KB
testcase_37 AC 7 ms
5,884 KB
testcase_38 AC 8 ms
5,884 KB
testcase_39 AC 7 ms
5,840 KB
testcase_40 AC 7 ms
6,064 KB
testcase_41 AC 7 ms
5,888 KB
testcase_42 AC 8 ms
5,836 KB
testcase_43 AC 7 ms
5,844 KB
testcase_44 AC 7 ms
5,868 KB
testcase_45 AC 150 ms
6,044 KB
testcase_46 AC 8 ms
5,836 KB
testcase_47 AC 54 ms
5,984 KB
testcase_48 AC 7 ms
6,052 KB
testcase_49 AC 314 ms
6,248 KB
testcase_50 AC 8 ms
5,836 KB
testcase_51 AC 8 ms
5,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

struct combi{
	deque<mint> kaijou;
	deque<mint> kaijou_;
	
	combi(int n){
		kaijou.push_back(1);
		for(int i=1;i<=n;i++){
			kaijou.push_back(kaijou[i-1]*i);
		}
		
		mint b=kaijou[n].inv();
		
		kaijou_.push_front(b);
		for(int i=1;i<=n;i++){
			int k=n+1-i;
			kaijou_.push_front(kaijou_[0]*k);
		}
	}
	
	mint combination(int n,int r){
		if(r>n)return 0;
		mint a = kaijou[n]*kaijou_[r];
		a *= kaijou_[n-r];
		return a;
	}
	
	mint junretsu(int a,int b){
		mint x = kaijou_[a]*kaijou_[b];
		x *= kaijou[a+b];
		return x;
	}
	
	mint catalan(int n){
		return combination(2*n,n)/(n+1);
	}
	
};
combi C(300000);

int main(){
	
	int N,M;
	cin>>N>>M;
	M = N*(N-1)/2 - M;
	if(M > N){
		cout<<0<<endl;
		return 0;
	}
	vector dp(N+1,vector<mint>(M+1,0));
	dp[0][0] = 1;
	rep(i,N){
		rep(j,M+1){
			for(int k=1;k<=N;k++){
				int ii = i+k;
				int jj = j+(k-1);
				if(ii>N||jj>M)break;
				if(k==1){
					dp[ii][jj] += dp[i][j];
				}
				else{
					dp[ii][jj] += dp[i][j] * C.combination(N-i-1,k-1) * C.kaijou[k] * C.kaijou_[2];
				}
			}
			for(int k=5;k<=N;k++){
				int ii = i+k;
				int jj = j+k;
				if(ii>N||jj>M)break;
				dp[ii][jj] += dp[i][j] * C.combination(N-i-1,k-1) * C.kaijou[k-1] * C.kaijou_[2];
			}
		}
	}
	/*
	rep(i,N+1){
		rep(j,M+1){
			cout<<dp[i][j].val()<<',';
		}
		cout<<endl;
	}
	*/
	cout<<dp[N][M].val()<<endl;
	
	return 0;
}
0