結果

問題 No.2530 Yellow Cards
ユーザー ks2mks2m
提出日時 2023-11-03 22:16:15
言語 Java21
(openjdk 21)
結果
AC  
実行時間 523 ms / 2,000 ms
コード長 1,185 bytes
コンパイル時間 2,627 ms
コンパイル使用メモリ 77,052 KB
実行使用メモリ 151,520 KB
最終ジャッジ日時 2023-11-03 22:16:27
合計ジャッジ時間 10,907 ms
ジャッジサーバーID
(参考情報)
judge11 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
53,388 KB
testcase_01 AC 52 ms
53,388 KB
testcase_02 AC 519 ms
151,492 KB
testcase_03 AC 143 ms
67,848 KB
testcase_04 AC 52 ms
53,328 KB
testcase_05 AC 515 ms
151,520 KB
testcase_06 AC 54 ms
53,380 KB
testcase_07 AC 518 ms
151,500 KB
testcase_08 AC 523 ms
149,464 KB
testcase_09 AC 513 ms
151,492 KB
testcase_10 AC 513 ms
151,456 KB
testcase_11 AC 514 ms
151,436 KB
testcase_12 AC 521 ms
151,496 KB
testcase_13 AC 513 ms
151,468 KB
testcase_14 AC 491 ms
145,404 KB
testcase_15 AC 453 ms
133,816 KB
testcase_16 AC 304 ms
115,268 KB
testcase_17 AC 489 ms
143,228 KB
testcase_18 AC 160 ms
70,904 KB
testcase_19 AC 89 ms
56,976 KB
testcase_20 AC 304 ms
115,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;

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

		int mod = 998244353;
		long ni = modinv(n, mod);
		int k2 = k / 2;
		long[][] dp = new long[k + 1][k2 + 2];
		dp[0][0] = 1;
		for (int i = 0; i < k; i++) {
			int end = i / 2;
			for (int j = 0; j <= end; j++) {
				int j1 = i - j * 2;
				dp[i + 1][j + 1] += dp[i][j] * j1 % mod * ni % mod;
				dp[i + 1][j] += dp[i][j] * (n - j1) % mod * ni % mod;
				dp[i + 1][j] %= mod;
			}
			dp[i + 1][end + 1] %= mod;
		}

		long ans = 0;
		for (int i = 0; i <= k2; i++) {
			ans += dp[k][i] * (n + i) % mod;
		}
		ans %= mod;
		System.out.println(ans);
	}

	static long modinv(long a, int m) {
		long b = m;
		long u = 1;
		long v = 0;
		long tmp = 0;

		while (b > 0) {
			long t = a / b;
			a -= t * b;
			tmp = a;
			a = b;
			b = tmp;

			u -= t * v;
			tmp = u;
			u = v;
			v = tmp;
		}

		u %= m;
		if (u < 0) u += m;
		return u;
	}
}
0