結果

問題 No.2381 Gift Exchange Party
ユーザー titiatitia
提出日時 2023-07-15 04:48:55
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 612 bytes
コンパイル時間 1,595 ms
コンパイル使用メモリ 86,912 KB
実行使用メモリ 107,816 KB
最終ジャッジ日時 2023-10-14 19:22:05
合計ジャッジ時間 8,820 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 104 ms
107,728 KB
testcase_01 AC 104 ms
103,684 KB
testcase_02 AC 106 ms
103,572 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 AC 105 ms
103,772 KB
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 AC 105 ms
103,596 KB
testcase_12 AC 106 ms
103,720 KB
testcase_13 AC 109 ms
103,744 KB
testcase_14 AC 119 ms
104,836 KB
testcase_15 AC 113 ms
104,264 KB
testcase_16 AC 108 ms
103,684 KB
testcase_17 AC 113 ms
103,736 KB
testcase_18 AC 110 ms
103,740 KB
testcase_19 AC 109 ms
103,812 KB
testcase_20 TLE -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

mod=998244353

FACT=[1]
for i in range(1,2*10**5+1):
    FACT.append(FACT[-1]*i%mod)

FACT_INV=[pow(FACT[-1],mod-2,mod)]
for i in range(2*10**5,0,-1):
    FACT_INV.append(FACT_INV[-1]*i%mod)

FACT_INV.reverse()

def Combi(a,b):
    if 0<=b<=a:
        return FACT[a]*FACT_INV[b]%mod*FACT_INV[a-b]%mod
    else:
        return 0

ANS=0

for i in range(0,10**5):
    if i*P>N:
        break

    x=Combi(N,i*P)

    now=i*P
    while now>0:
        x=x*Combi(now,now-P)%mod
        now-=P

    ANS+=x*FACT_INV[i]%mod*pow(FACT[P-1],i,mod)%mod
    ANS%=mod

print((FACT[N]-ANS)%mod)



0