Skip to content

Commit 912c406

Browse files
committed
[D2] Title: 달팽이 숫자, Time: 63 ms, Memory: 52,480 KB -BaekjoonHub
1 parent b6a53af commit 912c406

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# [D2] 달팽이 숫자 - 1954
2+
3+
[문제 링크](https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV5PobmqAPoDFAUq)
4+
5+
### 성능 요약
6+
7+
메모리: 52,480 KB, 시간: 63 ms, 코드길이: 621 Bytes
8+
9+
### 제출 일자
10+
11+
2025-05-12 07:54
12+
13+
14+
15+
> 출처: SW Expert Academy, https://swexpertacademy.com/main/code/problem/problemList.do
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
T = int(input())
2+
3+
for t in range(1, T+1):
4+
N = int(input())
5+
snail = [[0] * N for _ in range(N)]
6+
7+
dx = [0, 1, 0, -1]
8+
dy = [1, 0, -1, 0]
9+
10+
x, y = 0, 0
11+
direction = 0
12+
13+
for num in range(1, N*N + 1):
14+
snail[x][y] = num
15+
16+
nx = x + dx[direction]
17+
ny = y + dy[direction]
18+
19+
if nx < 0 or nx >= N or ny < 0 or ny >= N or snail[nx][ny] != 0:
20+
direction = (direction + 1) % 4
21+
nx = x + dx[direction]
22+
ny = y + dy[direction]
23+
24+
x, y = nx, ny
25+
26+
print(f"#{t}")
27+
for row in snail:
28+
print(*row)

0 commit comments

Comments
 (0)