結果
| 問題 |
No.2068 Restricted Permutation
|
| コンテスト | |
| ユーザー |
とりゐ
|
| 提出日時 | 2022-08-27 14:02:32 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 578 bytes |
| コンパイル時間 | 370 ms |
| コンパイル使用メモリ | 82,560 KB |
| 実行使用メモリ | 327,348 KB |
| 最終ジャッジ日時 | 2024-11-08 19:44:18 |
| 合計ジャッジ時間 | 4,854 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 RE * 10 TLE * 1 |
ソースコード
import sys
sys.setrecursionlimit(10**5)
mod=998244353
fact=[1]
for i in range(1,3010):
fact.append(fact[-1]*i%mod)
memo={}
def f(n,k,x):
if k==1:
res=fact[n-1]*(fact[n-1]-1)//2%mod+(x-1)*fact[n-1]%mod*fact[n-1]
return res%mod
if (n,k,x) in memo:
return memo[(n,k,x)]
res=0
if x-1>=0:
res+=(x-2)*(x-1)//2*fact[n-1]%mod*fact[n-2]
res+=(x-1)*f(n-1,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)*f(n-1,k-1,x)
res%=mod
memo[(n,k,x)]=res
return res
n,k,x=map(int,input().split())
print(f(n,k,x))
とりゐ