結果

問題 No.2528 pop_(backfront or not)
ユーザー keisuke6keisuke6
提出日時 2023-11-03 22:21:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 143 ms / 2,000 ms
コード長 1,242 bytes
コンパイル時間 1,944 ms
コンパイル使用メモリ 204,692 KB
実行使用メモリ 163,760 KB
最終ジャッジ日時 2023-11-03 22:21:25
合計ジャッジ時間 4,277 ms
ジャッジサーバーID
(参考情報)
judge13 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
163,644 KB
testcase_01 AC 67 ms
163,644 KB
testcase_02 AC 46 ms
163,644 KB
testcase_03 AC 46 ms
163,644 KB
testcase_04 AC 42 ms
163,760 KB
testcase_05 AC 44 ms
163,760 KB
testcase_06 AC 43 ms
163,760 KB
testcase_07 AC 47 ms
163,760 KB
testcase_08 AC 46 ms
163,760 KB
testcase_09 AC 53 ms
163,760 KB
testcase_10 AC 69 ms
163,760 KB
testcase_11 AC 69 ms
163,760 KB
testcase_12 AC 82 ms
163,760 KB
testcase_13 AC 84 ms
163,760 KB
testcase_14 AC 93 ms
163,760 KB
testcase_15 AC 121 ms
163,760 KB
testcase_16 AC 138 ms
163,760 KB
testcase_17 AC 143 ms
163,760 KB
testcase_18 AC 142 ms
163,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 998244353;
vector<long long> fact, fact_inv, inv;
void init_nCk(int SIZE) {
    fact.resize(SIZE + 5);
    fact_inv.resize(SIZE + 5);
    inv.resize(SIZE + 5);
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < SIZE + 5; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}
long long nCk(int n, int k) {
    if(n < k || n < 0 || k < 0) return 0;
    return fact[n] * (fact_inv[k] * fact_inv[n - k] % mod) % mod;
}
int m[4500][4500];
int f(int a, int b){
	if(a == 0 && b == 0){
		return 1;
	} 
	if(a < 0 || b < 0) return 0;
	if(m[a][b] != -1) return m[a][b];
	m[a][b] = (f(a-2,b)*nCk(a-1,2)+f(a,b-2)*nCk(b-1,2))%mod;
	if(a && b) m[a][b] = (m[a][b]+(f(a-1,b-1)%mod*((a*b-a-b+2)%mod))%mod)%mod;
	return m[a][b];
}
signed main(){
	init_nCk(100000);
	for(int i=0;i<4500;i++)for(int j=0;j<4500;j++) m[i][j] = -1;
	int N;
	cin>>N;
	for(int z=0;z<2*N+1;z++){
		int a = z, b = 2*N-z;
		cout<<f(a,b)<<endl;
	}
	/*for(int i=0;i<=2*N;i++){
		for(int j=0;j<=2*N;j++) cout<<m[i][j]<<' ';
		cout<<endl;
	}*/
}
0