結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,236 KB
testcase_01 AC 30 ms
10,236 KB
testcase_02 AC 31 ms
10,236 KB
testcase_03 AC 30 ms
10,236 KB
testcase_04 AC 31 ms
10,236 KB
testcase_05 AC 31 ms
10,236 KB
testcase_06 AC 32 ms
10,236 KB
testcase_07 AC 31 ms
10,236 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])
    num.pop(num.index(b[i]))
print(ans)
0