結果
問題 | No.1311 Reverse Permutation Index |
ユーザー |
![]() |
提出日時 | 2020-12-08 22:02:28 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 32 ms / 1,500 ms |
コード長 | 428 bytes |
コンパイル時間 | 77 ms |
コンパイル使用メモリ | 12,416 KB |
実行使用メモリ | 10,880 KB |
最終ジャッジ日時 | 2024-09-18 20:02:26 |
合計ジャッジ時間 | 886 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 6 |
ソースコード
import mathn, s = map(int, input().split())# 元の順列の復元P = []num = list(range(s))for i in reversed(range(s)):d, n = divmod(n, math.factorial(i))P.append(num.pop(d))# 逆置換作成R = [-1] * sfor i, p in enumerate(P):R[p] = i# 辞書順の位置ans = 0num = list(range(s))for i, v in enumerate(R, 1):ans += math.factorial(s - i) * num.index(v)num.pop(num.index(v))print(ans)