結果

問題 No.1311 Reverse Permutation Index
ユーザー titiatitia
提出日時 2020-12-08 01:20:46
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 27 ms / 1,500 ms
コード長 683 bytes
コンパイル時間 246 ms
コンパイル使用メモリ 11,924 KB
実行使用メモリ 10,128 KB
最終ジャッジ日時 2023-10-17 16:49:52
合計ジャッジ時間 831 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

N,S=map(int,input().split())

F=[1,1]
for i in range(1,20):
    F.append(F[-1]*i)

def calc(A):
    if len(A)==1:
        return 0
    compression_dict={a: ind for ind, a in enumerate(sorted(set(A)))}
    A=[compression_dict[a] for a in A]
    #print(A)

    return F[len(A)]*A[0]+calc(A[1:])

A=[]
USE=[0]*S
for i in range(S):
    uind=0
    while USE[uind]==1:
        uind+=1
        
    while N:
        if N>=F[S-i]:
            uind+=1
            N-=F[S-i]
        else:
            break
            
        while USE[uind]==1:
            uind+=1

    A.append(uind)
    USE[uind]=1

#print(A)
B=[]
for i in range(S):
    B.append(A.index(i))

print(calc(B))
            
0