結果

問題 No.2068 Restricted Permutation
ユーザー とりゐとりゐ
提出日時 2022-08-27 14:22:01
言語 PyPy3
(7.3.15)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 604 bytes
コンパイル時間 262 ms
コンパイル使用メモリ 82,588 KB
実行使用メモリ 150,076 KB
最終ジャッジ日時 2024-04-26 06:47:06
合計ジャッジ時間 8,496 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 328 ms
137,524 KB
testcase_01 AC 313 ms
137,648 KB
testcase_02 AC 320 ms
137,376 KB
testcase_03 AC 306 ms
137,516 KB
testcase_04 AC 303 ms
137,268 KB
testcase_05 AC 316 ms
137,504 KB
testcase_06 AC 314 ms
137,244 KB
testcase_07 AC 300 ms
137,260 KB
testcase_08 AC 304 ms
137,508 KB
testcase_09 AC 307 ms
137,784 KB
testcase_10 AC 302 ms
137,256 KB
testcase_11 AC 330 ms
137,268 KB
testcase_12 AC 323 ms
137,276 KB
testcase_13 AC 338 ms
137,520 KB
testcase_14 AC 312 ms
137,244 KB
testcase_15 AC 317 ms
137,496 KB
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
権限があれば一括ダウンロードができます

ソースコード

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