結果

問題 No.2068 Restricted Permutation
ユーザー とりゐとりゐ
提出日時 2022-08-27 14:22:01
言語 PyPy3
(7.3.15)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 604 bytes
コンパイル時間 431 ms
コンパイル使用メモリ 82,688 KB
実行使用メモリ 149,992 KB
最終ジャッジ日時 2024-11-08 19:45:04
合計ジャッジ時間 9,896 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 13 RE * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

mod=998244353

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

dp=[[0]*3010 for i in range(3010)]
N,K,X=map(int,input().split())
for k in range(1,3005):
  n=N-K+k
  if k==1:
    for x in range(1,3005):
      res=fact[n-1]*(fact[n-1]-1)//2%mod+(x-1)*fact[n-1]%mod*fact[n-1]
      dp[k][x]=res%mod
  else:
    for x in range(1,3005):
      res=0
      if x>1:
        res+=(x-2)*(x-1)//2*fact[n-1]%mod*fact[n-2]
        res+=(x-1)*dp[k-1][x-1]
      if n-x>=0:
        res+=(n*(n-1)-x*(x-1))//2*fact[n-1]%mod*fact[n-2]
        res+=(n-x)*dp[k-1][x]
      dp[k][x]=res%mod

print(dp[K][X])
0