Skip to content

Commit 5685dc2

Browse files
committed
[D2] Title: 달팽이 숫자, Time: 59 ms, Memory: 53,760 KB -BaekjoonHub
1 parent 1cf2157 commit 5685dc2

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

SWEA/D2/1954. 달팽이 숫자/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
### 성능 요약
66

7-
메모리: 52,480 KB, 시간: 63 ms, 코드길이: 621 Bytes
7+
메모리: 53,760 KB, 시간: 59 ms, 코드길이: 574 Bytes
88

99
### 제출 일자
1010

11-
2025-05-12 07:54
11+
2025-05-24 11:30
1212

1313

1414

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
T = int(input())
22

3-
for t in range(1, T+1):
3+
for tc in range(1, T+1):
44
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-
5+
6+
nums = [[0] * N for _ in range(N)]
7+
108
x, y = 0, 0
119
direction = 0
12-
13-
for num in range(1, N*N + 1):
14-
snail[x][y] = num
15-
10+
11+
dx = [0, 1, 0, -1]
12+
dy = [1, 0, -1, 0]
13+
14+
for i in range(1, N*N+1):
15+
nums[x][y] = i
16+
1617
nx = x + dx[direction]
1718
ny = y + dy[direction]
18-
19-
if nx < 0 or nx >= N or ny < 0 or ny >= N or snail[nx][ny] != 0:
19+
20+
if nx < 0 or nx >= N or ny < 0 or ny >= N or nums[nx][ny] != 0:
2021
direction = (direction + 1) % 4
2122
nx = x + dx[direction]
2223
ny = y + dy[direction]
23-
24+
2425
x, y = nx, ny
25-
26-
print(f"#{t}")
27-
for row in snail:
26+
27+
print(f"#{tc}")
28+
for row in nums:
2829
print(*row)

0 commit comments

Comments
 (0)