結果

問題 No.2381 Gift Exchange Party
ユーザー titiatitia
提出日時 2023-07-15 04:49:31
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 612 bytes
コンパイル時間 384 ms
コンパイル使用メモリ 86,616 KB
実行使用メモリ 138,740 KB
最終ジャッジ日時 2023-10-14 19:22:32
合計ジャッジ時間 7,582 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
138,336 KB
testcase_01 AC 125 ms
133,968 KB
testcase_02 AC 125 ms
133,688 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 AC 127 ms
133,688 KB
testcase_07 RE -
testcase_08 AC 121 ms
133,992 KB
testcase_09 RE -
testcase_10 RE -
testcase_11 AC 126 ms
133,768 KB
testcase_12 AC 123 ms
133,680 KB
testcase_13 AC 127 ms
133,732 KB
testcase_14 AC 141 ms
135,016 KB
testcase_15 AC 134 ms
134,388 KB
testcase_16 AC 130 ms
134,060 KB
testcase_17 AC 130 ms
134,012 KB
testcase_18 AC 127 ms
133,876 KB
testcase_19 AC 125 ms
133,904 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,4*10**5+1):
    FACT.append(FACT[-1]*i%mod)

FACT_INV=[pow(FACT[-1],mod-2,mod)]
for i in range(4*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