結果

問題 No.2528 pop_(backfront or not)
ユーザー ks2mks2m
提出日時 2023-11-03 21:49:46
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,973 ms / 2,000 ms
コード長 1,698 bytes
コンパイル時間 2,649 ms
コンパイル使用メモリ 77,428 KB
実行使用メモリ 200,668 KB
最終ジャッジ日時 2023-11-03 21:50:05
合計ジャッジ時間 16,061 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
53,520 KB
testcase_01 AC 57 ms
53,520 KB
testcase_02 AC 58 ms
53,520 KB
testcase_03 AC 57 ms
53,520 KB
testcase_04 AC 57 ms
52,464 KB
testcase_05 AC 80 ms
53,528 KB
testcase_06 AC 94 ms
54,152 KB
testcase_07 AC 129 ms
55,652 KB
testcase_08 AC 144 ms
57,656 KB
testcase_09 AC 237 ms
64,688 KB
testcase_10 AC 559 ms
88,336 KB
testcase_11 AC 596 ms
89,020 KB
testcase_12 AC 812 ms
116,068 KB
testcase_13 AC 883 ms
116,068 KB
testcase_14 AC 1,113 ms
134,784 KB
testcase_15 AC 1,632 ms
195,492 KB
testcase_16 AC 1,971 ms
200,516 KB
testcase_17 AC 1,946 ms
200,668 KB
testcase_18 AC 1,973 ms
195,844 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		br.close();

		int n2 = n * 2;
		int mod = 998244353;
		Kaijou kai = new Kaijou(n2, mod);
		long[][] dp = new long[n2 + 1][n2 + 1];
		dp[1][1] = 1;
		for (int i = 1; i < dp.length; i++) {
			for (int j = 1; j < dp.length; j++) {
				if (i == 1 && j == 1) {
					continue;
				}
				if (i >= 3) {
					dp[i][j] += kai.comb(i - 1, 2) * dp[i - 2][j] % mod;
				}
				if (j >= 3) {
					dp[i][j] += kai.comb(j - 1, 2) * dp[i][j - 2] % mod;
				}
				if (i >= 2 && j >= 2) {
					dp[i][j] += (long) (i - 1) * (j - 1) * dp[i - 1][j - 1] % mod;
				}
				dp[i][j] += dp[i - 1][j - 1];
				dp[i][j] %= mod;
			}
		}
		PrintWriter pw = new PrintWriter(System.out);
		for (int i = 1; i <= n2 + 1; i++) {
			pw.println(dp[i - 1][n2 + 1 - i]);
		}
		pw.flush();
	}

	static class Kaijou {
		long[] p, pi;
		int m;

		public Kaijou(int n, int mod) {
			n++;
			m = mod;
			p = new long[n];
			pi = new long[n];
			p[0] = 1;
			pi[0] = 1;
			for (int i = 1; i < n; i++) {
				p[i] = p[i - 1] * i % m;
			}
			pi[n - 1] = BigInteger.valueOf(p[n - 1])
					.modInverse(BigInteger.valueOf(m)).longValue();
			for (int i = n - 1; i > 1; i--) {
				pi[i - 1] = pi[i] * i % m;
			}
		}

		public long comb(int n, int r) {
			if (n < r) return 0;
			return p[n] * pi[r] % m * pi[n - r] % m;
		}

		public long perm(int n, int r) {
			if (n < r) return 0;
			return p[n] * pi[n - r] % m;
		}
	}
}
0