-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #585 from gmlrude/main
[박희경] 80차 라이브 코테 제출
- Loading branch information
Showing
3 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import sys | ||
from collections import * | ||
|
||
input = sys.stdin.readline | ||
|
||
n, k = map(int, input().split()) | ||
visited = [0] * (10 ** 5 + 1) | ||
|
||
|
||
def bfs(x): | ||
q = deque([x]) | ||
while q: | ||
x = q.popleft() | ||
if x == k: | ||
return visited[x] | ||
for nx in (x * 2, x - 1, x + 1): | ||
if 0 <= nx <= 10 ** 5 and not visited[nx]: | ||
if nx == 2 * x: | ||
visited[nx] = visited[x] | ||
else: | ||
visited[nx] = visited[x] + 1 | ||
q.append(nx) | ||
|
||
|
||
print(bfs(n)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import sys | ||
from collections import * | ||
|
||
input = sys.stdin.readline | ||
n, m = map(int, input().split()) | ||
floor = [list(map(str, input().rstrip())) for _ in range(n)] | ||
|
||
visited = [[0] * m for _ in range(n)] | ||
dx = [-1, 1, 0, 0] | ||
dy = [0, 0, -1, 1] | ||
|
||
|
||
def bfs(a, b, current): | ||
q = deque([(a, b)]) | ||
cnt = 1 | ||
if current == '|': | ||
direction_range = range(2) | ||
else: | ||
direction_range = range(2, 4) | ||
while q: | ||
x, y = q.popleft() | ||
for i in direction_range: | ||
nx, ny = x + dx[i], y + dy[i] | ||
if 0 <= nx < n and 0 <= ny < m and not visited[nx][ny]: | ||
if floor[nx][ny] == current: | ||
visited[nx][ny] = 1 | ||
q.append((nx, ny)) | ||
return cnt | ||
|
||
|
||
result = 0 | ||
for i in range(n): | ||
for j in range(m): | ||
if not visited[i][j]: | ||
result += bfs(i, j, floor[i][j]) | ||
|
||
print(result) | ||
|
||
""" | ||
6 9 | ||
-||--||-- | ||
--||--||- | ||
|--||--|| | ||
||--||--| | ||
-||--||-- | ||
--||--||- | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from collections import * | ||
|
||
|
||
def solution(prices): | ||
answer = [] | ||
|
||
queue = deque(prices) | ||
while queue: | ||
sec = 0 | ||
price = queue.popleft() | ||
for q in queue: | ||
sec += 1 | ||
if price > q: | ||
break | ||
answer.append(sec) | ||
|
||
return answer |