Please sign in first.
Submission #36265971
Source Code Expand
nn = 101
fa = [1] * (nn+1)
for i in range(nn):
fa[i+1] = fa[i] * (i+1)
def kth_permutation(n, k):
S = [i for i in range(n)]
L = []
for i in range(n):
a = fa[n-1-i]
j = k // a
k %= a
L.append(S[j])
S = S[:j] + S[j+1:]
return L
def id_of_permutation(L):
ret = 0
while len(L) > 1:
a = len([l for l in L if l < L[0]])
ret += a * fa[len(L) - 1]
L = L[1:]
return ret
N = int(input())
P = [int(a) - 1 for a in input().split()]
print(*[a + 1 for a in kth_permutation(N, id_of_permutation(P) - 1)])
Submission Info
| Submission Time | |
|---|---|
| Task | C - Previous Permutation |
| User | Kiri8128 |
| Language | PyPy3 (7.3.0) |
| Score | 300 |
| Code Size | 614 Byte |
| Status | AC |
| Exec Time | 65 ms |
| Memory | 65120 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 300 / 300 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | example_00.txt, example_01.txt |
| All | example_00.txt, example_01.txt, test_00.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| example_00.txt | AC | 65 ms | 62036 KiB |
| example_01.txt | AC | 47 ms | 62048 KiB |
| test_00.txt | AC | 54 ms | 65088 KiB |
| test_01.txt | AC | 51 ms | 63532 KiB |
| test_02.txt | AC | 53 ms | 65120 KiB |
| test_03.txt | AC | 48 ms | 61796 KiB |
| test_04.txt | AC | 51 ms | 64324 KiB |
| test_05.txt | AC | 48 ms | 62116 KiB |
| test_06.txt | AC | 51 ms | 64464 KiB |
| test_07.txt | AC | 52 ms | 64032 KiB |
| test_08.txt | AC | 48 ms | 61956 KiB |
| test_09.txt | AC | 52 ms | 63296 KiB |