結果

問題 No.2130 分配方法の数え上げ mod 998244353
ユーザー scrappyscrappy
提出日時 2022-11-25 23:26:21
言語 Go
(1.21.3)
結果
WA  
実行時間 -
コード長 662 bytes
コンパイル時間 11,515 ms
コンパイル使用メモリ 209,436 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-07-25 11:34:47
合計ジャッジ時間 13,229 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

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 := modpow(2, N, MOD)

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

		b = (b * (N - i) % MOD) % 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
}

func modpow(a int, n int, mod int) int {
	m := 1
	for n > 0 {
		if n&1 == 1 {
			m = (m * a) % mod
		}
		a = (a * a) % mod
		n >>= 1
	}
	return m
}
0