-
Notifications
You must be signed in to change notification settings - Fork 5
Minjeong / 4월 5주차 / 4문제 #205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,27 @@ | ||
| import sys | ||
| input = sys.stdin.readline | ||
|
|
||
| N, C = map(int, input().split()) # N: 집 개수, C: 공유기 개수 | ||
| houses = [int(input()) for _ in range(N)] # 집 좌표 리스트 | ||
| houses.sort() | ||
|
|
||
| left = 1 # 최소 거리 | ||
| right = houses[N-1] - houses[0] | ||
| result = 0 | ||
|
|
||
| while left <= right: | ||
| mid = (left + right) // 2 # 현재 설정된 거리 | ||
| cnt = 1 # 공유기 최소 1대 | ||
| check = houses[0] | ||
|
|
||
| for i in range(N): | ||
| if houses[i] - check >= mid: # 현재 설정된 거리 이상이면 공유기 개수 늘리기 | ||
| cnt += 1 | ||
| check = houses[i] | ||
| if cnt >= C: # 공유기 설치 수가 C 이상이면, 공유기간 거리 늘리기 | ||
| left = mid + 1 | ||
| result = max(result, mid) | ||
| else: # 공유기 설치 수가 C보다 미만이면, 공유기간 거리 줄이기 | ||
| right = mid - 1 | ||
|
|
||
| print(result) |
This file contains hidden or 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,19 @@ | ||
| import sys | ||
| input = sys.stdin.readline | ||
|
|
||
| K, N = map(int, input().split()) # K: 기존 랜선 수, N: 필요한 랜선 수 | ||
| arr = [int(input()) for _ in range(K)] | ||
|
|
||
| start = 1 | ||
| end = max(arr) | ||
|
|
||
| while start <= end: | ||
| mid = (start + end) // 2 # 현재 시도할 랜선 길이 | ||
| cnt = sum(x // mid for x in arr) # 해당 길이로 만들 수 있는 랜선 개수 | ||
|
|
||
| if cnt >= N: | ||
| start = mid + 1 # 더 길게 잘라도 됨 | ||
| else: | ||
| end = mid - 1 # 너무 길어서 N개 못 만듦 | ||
|
|
||
| print(end) # 조건을 만족하는 최대 길이 | ||
This file contains hidden or 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,39 @@ | ||
| import sys | ||
| from collections import deque | ||
| input = sys.stdin.readline | ||
|
|
||
| # 입력 처리 | ||
| N, M = map(int, input().split()) | ||
| graph = [list(map(int, input().strip())) for _ in range(N)] | ||
|
|
||
| def bfs(x, y): | ||
| # 방향: 상, 하, 좌, 우 | ||
| dx = [-1, 1, 0, 0] | ||
| dy = [0, 0, -1, 1] | ||
|
|
||
| queue = deque() | ||
| queue.append((x, y)) | ||
|
|
||
| while queue: | ||
| x, y = queue.popleft() | ||
|
|
||
| for i in range(4): | ||
| nx = x + dx[i] | ||
| ny = y + dy[i] | ||
|
|
||
| # 범위 벗어나면 무시 | ||
| if nx < 0 or nx >= N or ny < 0 or ny >= M: | ||
| continue | ||
|
|
||
| # 벽이면 무시 | ||
| if graph[nx][ny] == 0: | ||
| continue | ||
|
|
||
| # 이동 가능한 칸이면 거리 갱신 후 방문 처리 | ||
| if graph[nx][ny] == 1: | ||
| graph[nx][ny] = graph[x][y] + 1 | ||
| queue.append((nx, ny)) | ||
|
|
||
| return graph[N-1][M-1] | ||
|
|
||
| print(bfs(0, 0)) |
This file contains hidden or 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,43 @@ | ||
| import sys | ||
| from collections import deque | ||
| input = sys.stdin.readline | ||
|
|
||
| # 방향 벡터: 상, 하, 좌, 우 | ||
| dx = [-1, 1, 0, 0] | ||
| dy = [0, 0, -1, 1] | ||
|
|
||
| def bfs(start_x, start_y): | ||
| queue = deque() | ||
| queue.append((start_x, start_y)) | ||
| graph[start_x][start_y] = 0 # 방문 처리 | ||
| house_count = 1 # 단지 내 집 수 | ||
|
|
||
| while queue: | ||
| x, y = queue.popleft() | ||
| for i in range(4): # 상하좌우 탐색 | ||
| nx, ny = x + dx[i], y + dy[i] | ||
|
|
||
| # 좌표가 유효한지 확인 | ||
| if 0 <= nx < n and 0 <= ny < n and graph[nx][ny] == 1: | ||
| graph[nx][ny] = 0 # 방문 처리 | ||
| queue.append((nx, ny)) | ||
| house_count += 1 | ||
| return house_count | ||
|
|
||
| # 입력 | ||
| n = int(input()) | ||
| graph = [list(map(int, input().strip())) for _ in range(n)] | ||
|
|
||
| result = [] | ||
|
|
||
| # 모든 좌표 순회하며 BFS 수행 | ||
| for i in range(n): | ||
| for j in range(n): | ||
| if graph[i][j] == 1: | ||
| result.append(bfs(i, j)) | ||
|
|
||
| # 결과 출력 | ||
| result.sort() | ||
| print(len(result)) | ||
| for count in result: | ||
| print(count) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저는 아래처럼 작성했는데 for문을 리스트 컴프리헨션 사용해서 한 줄로 축약한 것이 인상적입니다.