結果
問題 | No.2068 Restricted Permutation |
ユーザー | とりゐ |
提出日時 | 2022-08-27 14:02:32 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 578 bytes |
コンパイル時間 | 299 ms |
コンパイル使用メモリ | 87,276 KB |
実行使用メモリ | 328,248 KB |
最終ジャッジ日時 | 2023-08-08 14:02:15 |
合計ジャッジ時間 | 6,233 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 73 ms
75,616 KB |
testcase_01 | AC | 74 ms
75,748 KB |
testcase_02 | AC | 72 ms
75,648 KB |
testcase_03 | AC | 73 ms
75,604 KB |
testcase_04 | AC | 77 ms
75,748 KB |
testcase_05 | AC | 73 ms
75,604 KB |
testcase_06 | AC | 72 ms
75,556 KB |
testcase_07 | AC | 72 ms
75,808 KB |
testcase_08 | AC | 72 ms
75,760 KB |
testcase_09 | AC | 73 ms
75,648 KB |
testcase_10 | AC | 71 ms
75,628 KB |
testcase_11 | AC | 71 ms
75,828 KB |
testcase_12 | AC | 73 ms
75,800 KB |
testcase_13 | AC | 1,617 ms
328,248 KB |
testcase_14 | AC | 100 ms
82,052 KB |
testcase_15 | AC | 151 ms
93,184 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))