Skip to content

Commit 31c9103

Browse files
Merge pull request #637 from baekhangyeol/main
[백한결] 94차 라이브 코테 제출
2 parents c779548 + a247d53 commit 31c9103

3 files changed

Lines changed: 79 additions & 0 deletions

File tree

live9/test94/문제1/백한결.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
def solution(dirs):
2+
visited = set()
3+
current = (0, 0)
4+
5+
move = {'U': (0, 1), 'D': (0, -1), 'R': (1, 0), 'L': (-1, 0)}
6+
7+
for dir in dirs:
8+
x = current[0] + move[dir][0]
9+
y = current[1] + move[dir][1]
10+
11+
if -5 <= x <= 5 and -5 <= y <= 5:
12+
visited.add(tuple(sorted([current, (x, y)])))
13+
print(visited)
14+
current = (x, y)
15+
16+
count = len(visited)
17+
18+
return count

live9/test94/문제2/백한결.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import heapq
2+
3+
def solution(book_time):
4+
5+
book_time.sort()
6+
7+
start = []
8+
end = []
9+
10+
for time in book_time:
11+
start.append(hourToMinute(time[0]))
12+
end.append(hourToMinute(time[1]) + 10)
13+
14+
rooms = []
15+
heapq.heapify(rooms)
16+
17+
for i in range(len(book_time)):
18+
if rooms and rooms[0] <= start[i]:
19+
heapq.heappop(rooms)
20+
21+
heapq.heappush(rooms, end[i])
22+
23+
return len(rooms)
24+
25+
def hourToMinute(time):
26+
hour, minute = time.split(":")
27+
28+
minutes = int(hour) * 60 + int(minute)
29+
30+
return minutes

live9/test94/문제3/백한결.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
def solution(stones, k):
2+
start = 1
3+
end = max(stones)
4+
max_friends = 0
5+
6+
while start <= end:
7+
mid = (start + end) // 2
8+
9+
if checkUnderZero(stones, k, mid):
10+
max_friends = mid
11+
start = mid + 1
12+
else:
13+
end = mid - 1
14+
15+
return max_friends
16+
17+
18+
# 징검다리 수에서 건너는 사람 수를 빼서 연속된 0이하의 수가 k를 초과하는지 검사
19+
def checkUnderZero(stones, k, friends):
20+
count = 0
21+
22+
for stone in stones:
23+
if stone - friends < 0:
24+
count += 1
25+
else:
26+
count = 0
27+
28+
if count >= k:
29+
return False
30+
31+
return True

0 commit comments

Comments
 (0)