結果

問題 No.1311 Reverse Permutation Index
ユーザー 37zigen37zigen
提出日時 2020-12-18 22:18:36
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 35 ms / 1,500 ms
コード長 389 bytes
コンパイル時間 82 ms
コンパイル使用メモリ 11,868 KB
実行使用メモリ 10,224 KB
最終ジャッジ日時 2023-10-21 08:25:13
合計ジャッジ時間 1,104 ms
ジャッジサーバーID
(参考情報)
judge13 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import math
N, S = map(int, input().split())
a = []
num = list(range(S))
for i in range(S):
    id = N // math.factorial(S - 1 - i)
    N %= math.factorial(S - 1 - i)
    a.append(num.pop(id))

b = [-1] * S

for i in range(S):
    b[a[i]] = i

num = list(range(S))

ans = 0
for i in range(S):
    ans += math.factorial(S - 1 - i) * num.index(b[i])
    del num[(num.index(b[i]))]
print(ans)
0