Skip to content

Commit 16dc681

Browse files
Merge pull request #652 from baekhangyeol/main
[백한결] 97차 라이브 코테 제출
2 parents 33c79ee + 054bcfe commit 16dc681

3 files changed

Lines changed: 89 additions & 0 deletions

File tree

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
def solution(board, skill):
2+
count = 0
3+
4+
prefix = [[0] * (len(board[0]) + 1) for _ in range(len(board) + 1)]
5+
6+
for type, r1, c1, r2, c2, degree in skill:
7+
8+
if type == 1:
9+
degree = -degree
10+
11+
prefix[r1][c1] += degree
12+
prefix[r1][c2 + 1] -= degree
13+
prefix[r2 + 1][c1] -= degree
14+
prefix[r2 + 1][c2 + 1] += degree
15+
16+
# 세로 누적합
17+
for i in range(len(board)):
18+
for j in range(len(board[0])):
19+
prefix[i][j + 1] += prefix[i][j]
20+
21+
# 가로 누적합
22+
for i in range(len(board)):
23+
for j in range(len(board[0])):
24+
prefix[i + 1][j] += prefix[i][j]
25+
26+
# prefix를 board에 반영
27+
for i in range(len(board)):
28+
for j in range(len(board[0])):
29+
board[i][j] += prefix[i][j]
30+
31+
if board[i][j] > 0:
32+
count += 1
33+
34+
return count

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
def solution(name):
2+
upDownmove = 0
3+
4+
# 조이스틱 위 아래 (최솟값)
5+
for spell in name:
6+
upDownmove += min(ord(spell) - ord('A'), ord('Z') - ord(spell) + 1)
7+
8+
# 조이스틱 오 왼
9+
# 조이스틱을 오른쪽으로만 계속 움직이는 경우
10+
rightLeftmove = len(name) - 1
11+
12+
# 조이스틱으로 오른쪽을 가다가 'A'를 만난 경우
13+
for i in range(len(name)):
14+
# 조이스틱 움직이는 횟수
15+
next = i + 1
16+
while len(name) > next and name[next] == 'A':
17+
next += 1
18+
19+
# 오른쪽으로 간 횟수, 오른쪽으로 가다가 A를 만나기 전까지의 움직임 횟수 중 최소의 2배 (앞으로 갔다가 뒤로 이동)
20+
# 오른쪽으로 간 횟수, 오른쪽으로 가다가 A를 만나기 전까지의 움직임 횟수 중 최대
21+
move = min(i, len(name) - next) * 2 + max(i, len(name) - next)
22+
rightLeftmove = min(rightLeftmove, move)
23+
24+
count = upDownmove + rightLeftmove
25+
26+
return count

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
def solution(distance, rocks, n):
2+
rocks.sort()
3+
4+
rocks = [0] + rocks + [distance]
5+
6+
left = 1
7+
right = distance
8+
9+
answer = 0
10+
11+
while left <= right:
12+
mid = (left + right) // 2
13+
14+
removedRock = 0
15+
prev = rocks[0]
16+
17+
for i in range(1, len(rocks)):
18+
if rocks[i] - prev < mid:
19+
removedRock += 1
20+
else:
21+
prev = rocks[i]
22+
23+
if removedRock > n:
24+
right = mid - 1
25+
else:
26+
answer = mid
27+
left = mid + 1
28+
29+
return answer

0 commit comments

Comments
 (0)