結果
問題 | No.2068 Restricted Permutation |
ユーザー | とりゐ |
提出日時 | 2022-08-27 14:02:32 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 578 bytes |
コンパイル時間 | 413 ms |
コンパイル使用メモリ | 82,972 KB |
実行使用メモリ | 329,612 KB |
最終ジャッジ日時 | 2024-04-26 06:46:26 |
合計ジャッジ時間 | 4,215 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 36 ms
59,168 KB |
testcase_01 | AC | 38 ms
59,544 KB |
testcase_02 | AC | 38 ms
59,044 KB |
testcase_03 | AC | 41 ms
58,448 KB |
testcase_04 | AC | 38 ms
58,692 KB |
testcase_05 | AC | 40 ms
58,288 KB |
testcase_06 | AC | 42 ms
59,568 KB |
testcase_07 | AC | 41 ms
58,560 KB |
testcase_08 | AC | 37 ms
58,968 KB |
testcase_09 | AC | 35 ms
59,492 KB |
testcase_10 | AC | 38 ms
60,076 KB |
testcase_11 | AC | 38 ms
59,608 KB |
testcase_12 | AC | 38 ms
60,384 KB |
testcase_13 | AC | 1,742 ms
329,612 KB |
testcase_14 | AC | 66 ms
78,884 KB |
testcase_15 | AC | 115 ms
91,104 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 | - |
ソースコード
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))