Skip to content

Commit b1838be

Browse files
Merge pull request #646 from gmlrude/main
[박희경] 96차 라이브 코테 제출
2 parents 835ded5 + e0054e3 commit b1838be

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

live9/test96/문제1/박희경.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from collections import *
2+
3+
def solution(board):
4+
# 상하좌우
5+
dx = [0, 0, -1, 1]
6+
dy = [1, -1, 0, 0]
7+
8+
n = len(board)
9+
m = len(board[0])
10+
11+
def bfs(x, y, move):
12+
q = deque([(x, y, move)])
13+
visited = [[0] * m for _ in range(n)]
14+
visited[x][y] = 1
15+
16+
while q:
17+
x, y, move = q.popleft()
18+
if board[x][y] == 'G':
19+
return move
20+
# 'D' 만날 때까지 이동
21+
for i in range(4):
22+
nx, ny = x, y
23+
while 0 <= nx + dx[i] < n and 0 <= ny + dy[i] < m and board[nx + dx[i]][ny + dy[i]] != 'D':
24+
nx += dx[i]
25+
ny += dy[i]
26+
if not visited[nx][ny]:
27+
visited[nx][ny] = 1
28+
q.append((nx, ny, move + 1))
29+
return -1
30+
31+
32+
for i in range(n):
33+
for j in range(m):
34+
if board[i][j] == 'R':
35+
return bfs(i, j, 0)

live9/test96/문제2/박희경.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
def solution(n):
2+
answer = 0
3+
4+
start, end = 1, 1
5+
total = 1
6+
while end <= n:
7+
if total == n:
8+
answer += 1
9+
end += 1
10+
total += end
11+
elif total < n:
12+
end += 1
13+
total += end
14+
else:
15+
total -= start
16+
start += 1
17+
18+
return answer

live9/test96/문제3/박희경.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
def solution(elements):
2+
answer = set()
3+
4+
n = len(elements)
5+
elements = elements * 2
6+
7+
for i in range(n) :
8+
for j in range(n) :
9+
answer.add(sum(elements[j:j+i+1]))
10+
11+
return len(answer)

0 commit comments

Comments
 (0)