-
Notifications
You must be signed in to change notification settings - Fork 0
/
9663.py
38 lines (30 loc) · 990 Bytes
/
9663.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import sys
input = sys.stdin.readline
result = 0
def dfs(count):
global result
if count == N:
result += 1
for i in range(0, N):
for j in range(0, N):
if visited[i][j]:
continue
visited[i][j] = True
for a in range(N):
visited[i][a] = True # 수평선
visited[a][j] = True # 수직선
for a in range(N):
if 0 <= i + a < N and 0 <= j + a < N:
visited[i + a][j + a] = True
if 0 <= i - a < N and 0 <= j - a < N:
visited[i - a][j - a] = True
# 부 대각선
if 0 <= i + a < N and 0 <= j - a < N:
visited[i + a][j - a] = True
if 0 <= i - a < N and 0 <= j + a < N:
visited[i - a][j + a] = True
dfs(count + 1)
N = int(input())
visited = [[False] * N for _ in range(N)]
dfs(1)
print(result)