Skip to content

Commit 104d9cb

Browse files
Merge pull request #649 from gmlrude/main
[박희경] 97차 라이브 코테 제출
2 parents b0fc3df + 03eb68f commit 104d9cb

3 files changed

Lines changed: 89 additions & 0 deletions

File tree

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
def solution(board, skill):
2+
answer = 0
3+
4+
n = len(board)
5+
m = len(board[0])
6+
7+
degree = [[0] * (m + 1) for _ in range(n + 1)]
8+
for type, r1, c1, r2, c2, d in skill:
9+
if type == 1: d = -d
10+
degree[r1][c1] += d
11+
degree[r1][c2 + 1] -= d
12+
degree[r2 + 1][c1] -= d
13+
degree[r2 + 1][c2 + 1] += d
14+
15+
for i in range(n - 1):
16+
for j in range(m):
17+
degree[i+1][j] += degree[i][j]
18+
19+
for j in range(m):
20+
for i in range(n):
21+
degree[i][j+1] += degree[i][j]
22+
23+
24+
for i in range(n):
25+
for j in range(m):
26+
board[i][j] += degree[i][j]
27+
if board[i][j] > 0:
28+
answer += 1
29+
return answer

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
def solution(name):
2+
answer = 0
3+
4+
min_move = len(name) - 1 # 한칸씩 이동하는 경우
5+
6+
for i, char in enumerate(name):
7+
# 위 아래로 움직일 때
8+
answer += min(ord(char) - ord('A'), ord('Z') - ord(char) + 1)
9+
10+
# 연속된 A 끝나는 인덱스 찾기
11+
next = i + 1
12+
while next < len(name) and name[next] == 'A':
13+
next += 1
14+
15+
"""
16+
len(name) - next : 'A' 구간이 끝난 후 남은 문자의 수
17+
1. 오른쪽으로 하나씩 가기 (최악의 경우)
18+
2. i까지 갔다가 → 되돌아와서(*2) → 남은 부분 끝까지 가기
19+
3. 뒷부분(next 이후)까지 갔다가 → 되돌아와서(*2) → 앞부분(i)까지 가기
20+
"""
21+
min_move = min(min_move,
22+
2 * i + len(name) - next,
23+
i + 2 * (len(name) - next)
24+
)
25+
26+
answer += min_move
27+
28+
29+
return answer

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
def solution(distance, rocks, n):
2+
answer = 0
3+
4+
rocks.append(distance)
5+
rocks.sort()
6+
7+
start, end = 0, distance
8+
while start <= end:
9+
mid = (start + end) // 2 # 최소 거리
10+
11+
current = 0 # 출발지점
12+
remove_cnt = 0
13+
14+
for rock in rocks:
15+
diff = rock - current # 바위 간의 거리
16+
if diff < mid: # 최소 거리로 설정한 값(mid)보다 작다면 제거하기
17+
remove_cnt += 1
18+
else:
19+
current = rock
20+
if remove_cnt > n:
21+
break
22+
23+
if remove_cnt > n: # mid 값이 컸다는 의미니까
24+
end = mid - 1
25+
else:
26+
answer = mid
27+
start = mid + 1
28+
29+
30+
31+
return answer

0 commit comments

Comments
 (0)