結果
| 問題 | No.1311 Reverse Permutation Index |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-12-08 10:06:21 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 619 bytes |
| 記録 | |
| コンパイル時間 | 107 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 10,880 KB |
| 最終ジャッジ日時 | 2024-09-17 14:28:09 |
| 合計ジャッジ時間 | 1,164 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 4 WA * 2 |
ソースコード
N, S = map(int, input().split())
factorial = [1]
for i in range(1, S + 1):
factorial.append(factorial[-1] * i)
def f(x):
"""x番目の順列が何か求める。O(S^2)"""
cur = x
numbers = list(range(1, S + 1))
res = []
for i in range(1, S + 1):
d, cur = divmod(cur, factorial[S - i])
res.append(numbers[d])
numbers.pop(d)
return res
perm = f(N)
inv_perm = [0] * S
for i, x in enumerate(perm, 1):
inv_perm[x - 1] = i
# bisect
l, r = 0, factorial[S]
while r - l > 1:
m = (r + l) // 2
if f(m) < inv_perm:
l = m
else:
r = m
print(r)