結果

問題 No.1311 Reverse Permutation Index
ユーザー googol_S0googol_S0
提出日時 2020-12-08 00:04:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 36 ms / 1,500 ms
コード長 367 bytes
コンパイル時間 172 ms
コンパイル使用メモリ 81,880 KB
実行使用メモリ 53,560 KB
最終ジャッジ日時 2023-10-17 16:45:58
合計ジャッジ時間 1,137 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

N,S=map(int,input().split())
P=list(range(S))
X=[]
for i in range(1,S+1):
  X.append(N%i)
  N//=i
X=X[::-1]
Q=[]
for i in range(S):
  Q.append(P[X[i]])
  del P[X[i]]
D=dict()
for i in range(S):
  D[Q[i]]=i
R=[D[i] for i in range(S)]
P=list(range(S))
A=0
F=1
for i in range(S):
  F*=i+1
for i in range(S):
  F//=S-i
  A+=P.index(R[i])*F
  del P[P.index(R[i])]
print(A)
0