complete 9663_bt.py for pypy3

This commit is contained in:
2024-04-30 15:53:18 +09:00
parent a01bed67b5
commit b51c82bb04
2 changed files with 39 additions and 0 deletions

39
zeta_python/9663_bt.py Normal file
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)))

View File