結果

問題 No.1311 Reverse Permutation Index
ユーザー KudeKude
提出日時 2020-12-08 01:28:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 46 ms / 1,500 ms
コード長 637 bytes
コンパイル時間 231 ms
コンパイル使用メモリ 81,868 KB
実行使用メモリ 63,600 KB
最終ジャッジ日時 2023-10-17 16:50:03
合計ジャッジ時間 1,069 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

n, s = map(int, input().split())

def fact(n):
    return 1 if n <= 1 else n * fact(n - 1)

p = []
used = [False] * s
for i in range(s):
    for x in range(s):
        if used[x]:
            continue
        if n >= fact(s - 1 - i):
            n -= fact(s - 1 - i)
        else:
            p.append(x)
            used[x] = True
            break
q = [None] * s
for i in range(s):
    q[p[i]] = i

ans = 0
used = [False] * s
for i in range(s):
    for x in range(s):
        if used[x]:
            continue
        if x != q[i]:
            ans += fact(s - 1 - i)
        else:
            used[x] = True
            break
print(ans)
0