complete 9663_bt.py for pypy3

This commit is contained in:
yenru0 committed 2024-04-30 15:53:18 +09:00
1 parent a01bed67b5
commit b51c82bb04
2 files changed
+39

No files matched your search

+39
View File
@@ -0,0 +1,39 @@
import sys
input = sys.stdin.readline
print = sys.stdout.write
N = int(input())
def solve(N: int) -> int:
count = 0
D = []
for i in range(N):
T = [i]
D.append((1, T))
while D:
now, xs = D.pop()
if now == N:
count += 1
continue
for i in range(N):
if i in xs:
continue
flag = True
for j in range(now):
y = xs[j]
if abs(now - j) == abs(y - i):
flag = False
break
if flag:
D.append((now + 1, xs + [i]))
return count
if __name__ == "__main__":
print(str(solve(N)))
Whitespace-only changes.