結果

問題 No.2135 C5
ユーザー shobonvipshobonvip
提出日時 2022-10-21 09:34:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,219 bytes
コンパイル時間 8,226 ms
コンパイル使用メモリ 262,224 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-09-13 11:47:56
合計ジャッジ時間 8,437 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 2 ms
4,380 KB
testcase_07 WA -
testcase_08 AC 2 ms
4,376 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 WA -
testcase_37 AC 1 ms
4,380 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 1 ms
4,380 KB
testcase_43 AC 2 ms
4,376 KB
testcase_44 AC 2 ms
4,376 KB
testcase_45 AC 92 ms
4,380 KB
testcase_46 AC 2 ms
4,380 KB
testcase_47 AC 33 ms
4,376 KB
testcase_48 AC 2 ms
4,380 KB
testcase_49 AC 192 ms
4,376 KB
testcase_50 AC 1 ms
4,376 KB
testcase_51 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

typedef modint998244353 mint;
typedef long long ll;

//defmodfact
const int COMinitMAX = 500;
mint fact[COMinitMAX+1], factinv[COMinitMAX+1];

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

mint cmb(int a, int b){
	if (a<b || b<0) return mint(0);
	return fact[a]*factinv[b]*factinv[a-b];
}
//--------


int main(){
	modfact();
	int n, m;
	cin >> n >> m;

	if (m < n*(n-1)/2 - n){
		cout << 0 << endl;
		return 0;
	}

	mint inv2 = mint(2).inv();
	vector<vector<mint>> dp(n+1, vector<mint>(n+1));
	dp[0][0] = 1;
	for (int i=0; i<n+1; i++){
		for (int j=0; j<n+1; j++){
			if (i+1 <= n) dp[i+1][j] += dp[i][j];
			for (int k=2; k<=min(n-i, n-j+1); k++){
				dp[i+k][j+k-1] += cmb(n-i-1, k-1) * dp[i][j] * fact[k] * inv2;
			}
			for (int k=5; k<=min(n-i, n-j); k++){
				dp[i+k][j+k] += cmb(n-i-1, k-1) * dp[i][j] * fact[k-1] * inv2;
			}
		}
	}

	mint ans = 0;
	for (int i=n*(n-1)/2-m; i<=n; i++){
		ans += dp[n][i];
	}
	cout << ans.val() << endl;

}
0