結果

問題 No.2381 Gift Exchange Party
ユーザー miya145592miya145592
提出日時 2023-07-14 22:51:43
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,012 bytes
コンパイル時間 840 ms
コンパイル使用メモリ 86,940 KB
実行使用メモリ 150,144 KB
最終ジャッジ日時 2023-10-14 13:11:33
合計ジャッジ時間 6,714 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
78,128 KB
testcase_01 AC 75 ms
71,372 KB
testcase_02 AC 102 ms
96,516 KB
testcase_03 AC 91 ms
83,188 KB
testcase_04 AC 114 ms
107,468 KB
testcase_05 AC 145 ms
137,464 KB
testcase_06 AC 108 ms
103,076 KB
testcase_07 AC 109 ms
103,348 KB
testcase_08 AC 137 ms
129,692 KB
testcase_09 AC 81 ms
75,924 KB
testcase_10 AC 99 ms
93,424 KB
testcase_11 AC 118 ms
112,076 KB
testcase_12 AC 85 ms
77,720 KB
testcase_13 AC 109 ms
96,548 KB
testcase_14 AC 141 ms
117,400 KB
testcase_15 AC 105 ms
91,236 KB
testcase_16 AC 103 ms
93,704 KB
testcase_17 AC 143 ms
129,904 KB
testcase_18 AC 117 ms
103,328 KB
testcase_19 AC 120 ms
107,560 KB
testcase_20 TLE -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

def nPr(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    return g1[n] * g2[n-r] % mod

def nCr(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return (g1[n] * g2[r] % mod) * g2[n-r] % mod

MOD = 998244353
N, P = map(int, input().split())

g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
fact = [1, 1]
fact_inv = [1, 1]

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % MOD )
    inverse.append( ( -inverse[MOD % i] * (MOD//i) ) % MOD )
    g2.append( (g2[-1] * inverse[-1]) % MOD )
    fact.append( (fact[-1] * i) % MOD )
    fact_inv.append(fact_inv[-1] * inverse[-1] % MOD)

all = fact[N]

ng = 1
for i in range(1, N+1):
    if P*i>N:
        break
    tmp = 1
    j = 0
    while j<i:
        tmp *= nCr(N-P*j, P, MOD)
        tmp %= MOD
        tmp *= fact[P-1]
        tmp %= MOD
        j+=1
    tmp *= fact_inv[i]
    tmp %= MOD
    ng += tmp
    ng %= MOD

ans = (all-ng)%MOD
print(ans)
0