QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#281432 | #7778. Turning Permutation | ucup-team2000# | WA | 13ms | 8280kb | Python3 | 948b | 2023-12-10 04:59:48 | 2023-12-10 04:59:48 |
Judging History
answer
import sys
f = [[0], [0, 1]]
for n in range(2, 55):
f.append([])
for i in range(0, n + 1):
sum = 0
for k in range(n - i, n):
sum = sum + f[n - 1][k]
f[n].append(sum)
pow = [1]
for n in range(1, 55):
pow.append(pow[n - 1] * n)
inp = sys.stdin.readline().split(' ')
n, k = int(inp[0]), int(inp[1])
perm = []
for p in range(n):
i = 1
while True:
if i > n - p:
print(-1)
exit(0)
tmp = pow[n - p - 1] // pow[n - p - i] // pow[i - 1] * f[i][1] * f[n - p - i + 1][1]
if (tmp < k):
k = k - tmp
i = i + 1
else:
break
perm.append(i - 1)
rem = list(range(1, n + 1))
output = []
for p in range(n):
q = rem[perm[p]]
output.append(q)
rem.remove(q)
print(q, end='')
if (p == n - 1):
print('')
else:
print(' ', end='')
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 13ms
memory: 8144kb
input:
3 2
output:
2 1 3
result:
ok 3 number(s): "2 1 3"
Test #2:
score: 0
Accepted
time: 12ms
memory: 8280kb
input:
3 5
output:
-1
result:
ok 1 number(s): "-1"
Test #3:
score: 0
Accepted
time: 4ms
memory: 8144kb
input:
4 6
output:
3 1 2 4
result:
ok 4 number(s): "3 1 2 4"
Test #4:
score: 0
Accepted
time: 5ms
memory: 8104kb
input:
4 11
output:
-1
result:
ok 1 number(s): "-1"
Test #5:
score: -100
Wrong Answer
time: 7ms
memory: 8188kb
input:
3 1
output:
1 2 3
result:
wrong answer 2nd numbers differ - expected: '3', found: '2'