File tree Expand file tree Collapse file tree 2 files changed +43
-0
lines changed
Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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 )
You can’t perform that action at this time.
0 commit comments