結果

問題 No.2381 Gift Exchange Party
ユーザー flygonflygon
提出日時 2023-07-14 21:55:39
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,030 bytes
コンパイル時間 331 ms
コンパイル使用メモリ 87,032 KB
実行使用メモリ 123,496 KB
最終ジャッジ日時 2023-10-14 12:03:35
合計ジャッジ時間 6,814 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
71,764 KB
testcase_01 AC 88 ms
71,744 KB
testcase_02 WA -
testcase_03 AC 112 ms
81,572 KB
testcase_04 AC 121 ms
96,148 KB
testcase_05 AC 146 ms
114,056 KB
testcase_06 AC 119 ms
93,708 KB
testcase_07 AC 121 ms
93,496 KB
testcase_08 AC 138 ms
109,380 KB
testcase_09 AC 104 ms
77,244 KB
testcase_10 AC 115 ms
87,704 KB
testcase_11 AC 123 ms
98,808 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 TLE -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(5*10**5)
input = sys.stdin.readline
from collections import defaultdict, deque, Counter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right
from math import gcd

n,p = map(int,input().split())
all = 1
mod = 998244353
for i in range(1,n+1):
    all *= i
    all %= mod
e = 1
for i in range(1, p):
    e *= i
    e %= mod

# nCk
def com(n, mod):
    fact = [1, 1]
    factinv = [1, 1]
    inv = [0, 1]
    for i in range(2, n+1):
        fact.append((fact[-1]*i) % mod)
        inv.append((-inv[mod % i]*(mod//i)) % mod)
        factinv.append((factinv[-1]*inv[-1]) % mod)
    return fact, factinv

f,fi = com(n, mod)

def npr(n, r,):
    if n < r:return 1
    return f[n] * fi[n-r] % mod
def ncr(n, r):
    if n < r:return 1
    return f[n] * fi[n-r] % mod * fi[r] % mod
# 長さ1とpのループしかないとき

mx = n//p
now = 1
for i in range(mx+1):
    now *= ncr(p*i,p)
    now %= mod
    all -= ncr(n,n-p*i) * now * pow(e, i, mod)
    all %= mod


print(all)

0