Skip to content

Commit 6a33be1

Browse files
Create solution.py
1 parent 7c6fb30 commit 6a33be1

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
from typing import List
2+
from math import factorial
3+
import heapq
4+
5+
class Solution:
6+
def permute(self, xxy: int, yyz: int) -> List[int]:
7+
8+
kasu = {}
9+
nnss = []
10+
majs = []
11+
ajwi = heapq.heappush
12+
laoq = []
13+
14+
zzp = [i for i in range(1, xxy + 1) if i % 2 == 1]
15+
zzq = [i for i in range(1, xxy + 1) if i % 2 == 0]
16+
17+
ppp = []
18+
nxr = None
19+
20+
for pps in range(xxy):
21+
if pps == 0:
22+
cnd = sorted(zzp + zzq)
23+
else:
24+
cnd = zzp if nxr == 1 else zzq
25+
26+
fff = False
27+
for cndt in cnd:
28+
if cndt % 2 == 1:
29+
nxt = 0
30+
noo = len(zzp) - 1
31+
nee = len(zzq)
32+
else:
33+
nxt = 1
34+
noo = len(zzp)
35+
nee = len(zzq) - 1
36+
37+
llq = noo + nee
38+
if llq == 0:
39+
cnt = 1
40+
else:
41+
if nxt == 1:
42+
if noo != (llq + 1) // 2 or nee != llq // 2:
43+
cnt = 0
44+
else:
45+
cnt = factorial(noo) * factorial(nee)
46+
else:
47+
if nee != (llq + 1) // 2 or noo != llq // 2:
48+
cnt = 0
49+
else:
50+
cnt = factorial(noo) * factorial(nee)
51+
52+
ajwi(nnss, cnt)
53+
ajwi(majs, llq)
54+
55+
if cnt >= yyz:
56+
ppp.append(cndt)
57+
if cndt % 2 == 1:
58+
zzp.remove(cndt)
59+
nxr = 0
60+
else:
61+
zzq.remove(cndt)
62+
nxr = 1
63+
fff = True
64+
break
65+
else:
66+
yyz -= cnt
67+
68+
ajwi(laoq, len(ppp))
69+
70+
if not fff:
71+
return []
72+
return ppp

0 commit comments

Comments
 (0)