結果

問題 No.2130 分配方法の数え上げ mod 998244353
ユーザー scrappyscrappy
提出日時 2022-11-25 23:11:58
言語 Go
(1.22.1)
結果
TLE  
実行時間 -
コード長 532 bytes
コンパイル時間 13,101 ms
コンパイル使用メモリ 242,368 KB
実行使用メモリ 13,884 KB
最終ジャッジ日時 2024-04-10 04:16:27
合計ジャッジ時間 17,029 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
13,884 KB
testcase_01 AC 2 ms
6,812 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 1 ms
6,944 KB
testcase_12 AC 1 ms
6,944 KB
testcase_13 AC 1 ms
6,940 KB
testcase_14 AC 1 ms
6,940 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 1 ms
6,940 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 3 ms
6,940 KB
testcase_19 AC 4 ms
6,940 KB
testcase_20 AC 19 ms
6,944 KB
testcase_21 TLE -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

// No.2130 分配方法の数え上げ mod 998244353
package main

import "fmt"

const MOD = 998_244_353

func main() {
	var N, M int
	fmt.Scan(&N, &M)

	a := 1
	for i := 0; i < N; i++ {
		a = a * 2 % MOD
	}
	b := 1
	for i := 0; i < M; i++ {
		a = (a - b + MOD) % MOD

		b = (b * (N - i)) % MOD
		b = (b * modinv(i+1, MOD)) % MOD
	}
	fmt.Println(a)
}

func modinv(a, m int) int {
	b := m
	u := 1
	v := 0
	for b != 0 {
		t := a / b
		a -= t * b
		a, b = b, a
		u -= t * v
		u, v = v, u
	}
	u %= m
	if u < 0 {
		u += m
	}
	return u
}
0