結果

問題 No.1311 Reverse Permutation Index
ユーザー Kiri8128Kiri8128
提出日時 2020-12-08 01:43:36
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 29 ms / 1,500 ms
コード長 543 bytes
コンパイル時間 106 ms
コンパイル使用メモリ 12,000 KB
実行使用メモリ 10,188 KB
最終ジャッジ日時 2023-10-17 16:50:32
合計ジャッジ時間 889 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

fact = [1]
for i in range(100):
    fact.append(fact[-1] * (i+1))

def IDtoL(L, id):
    n = len(L)
    if n == 0: return []
    l = [a for a in L]
    t = l.pop(id//fact[n-1])
    return [t] + IDtoL(l, id % fact[n-1])

def LtoID(L):
    n = len(L)
    if n == 1: return 0
    a =  len([l for l in L if l < L[0]])
    return a * fact[n-1] + LtoID(L[1:])

def rev(A):
    n = len(A)
    B = [-1] * n
    for i, a in enumerate(A):
        B[a] = i
    return B

N, S = map(int, input().split())
print(LtoID(rev(IDtoL([a for a in range(S)], N))))
0