結果

問題 No.1311 Reverse Permutation Index
ユーザー tktk_snsntktk_snsn
提出日時 2020-12-08 22:02:28
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 32 ms / 1,500 ms
コード長 428 bytes
コンパイル時間 76 ms
コンパイル使用メモリ 11,928 KB
実行使用メモリ 10,236 KB
最終ジャッジ日時 2023-10-19 00:03:40
合計ジャッジ時間 888 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
10,236 KB
testcase_01 AC 30 ms
10,236 KB
testcase_02 AC 29 ms
10,236 KB
testcase_03 AC 29 ms
10,236 KB
testcase_04 AC 29 ms
10,236 KB
testcase_05 AC 31 ms
10,236 KB
testcase_06 AC 31 ms
10,236 KB
testcase_07 AC 30 ms
10,236 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
n, 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] * s
for i, p in enumerate(P):
    R[p] = i

# 辞書順の位置
ans = 0
num = 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)
0