-
Notifications
You must be signed in to change notification settings - Fork 1
Conversation
늦어서 죄송합니다 여러분들 ㅠㅠㅠㅠ |
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.
풀이 고생하셨습니다 우열님. BFS로 깔끔하게 로직을 작성하셨네요. 모든 알파벳에 대한 경우의 수를 구해놓고 효율적으로 답을 도출할 수 있게 잘 풀이하신 것 같습니다.
answer_dict[text] += 1 | ||
|
||
# 문자열의 길이가 5 이상이라면 더 이상 검색하지 않는다. | ||
if len(text) >= 5: |
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.
큐에 삽입할 때(52번 라인) 이 조건문을 추가해주면 연산 횟수도 줄고 조금 더 깔끔해지지 않을까 싶습니다!
N, M, K = map(int, input().split()) | ||
|
||
# N by M 의 격자 | ||
table = [] |
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.
별 다른 추가 연산이 없기 때문에 57 ~ 59번 라인을 table = [input().rstrip() for _ in range(N)]
으로 가능! 파이써닉하게 가봅시다
answer_dict = defaultdict(int) | ||
for row_i, row in enumerate(table): | ||
for col_i, col in enumerate(row): | ||
bfs(row_i, col_i) |
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.
우열님 이부분은 range(len())
을 사용하셔도 괜찮을 것 같습니다!!
제 로컬 IDE 에서 돌려보니 약 1.75 배정도 속도차이가 나네요!
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.
도현님이 코멘트 남겨주신 것처럼, 위에서 table의 크기인 N과 M 주어지기 때문에
for row_i in range(N):
for col_i in range(M):
bfs(row_i, col_i)
로 쓰시면 더 깔끔하고 빠를것 같아요~!!!
answer_dict = defaultdict(int) | ||
for row_i, row in enumerate(table): | ||
for col_i, col in enumerate(row): | ||
bfs(row_i, col_i) |
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.
도현님이 코멘트 남겨주신 것처럼, 위에서 table의 크기인 N과 M 주어지기 때문에
for row_i in range(N):
for col_i in range(M):
bfs(row_i, col_i)
로 쓰시면 더 깔끔하고 빠를것 같아요~!!!
# 상, 하, 좌, 우, 대각선 왼쪽 위, 대각선 오른쪽 위, 대각선 왼쪽 아래, 대각선 오른쪽 아래 | ||
directions = ((-1,0),(1,0),(0,-1),(0,1),(-1,-1),(-1,1),(1,-1),(1,1)) | ||
|
||
def bfs(x, y): |
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.
저는 DFS로 풀이했는데, 우열님께서 BFS로 깔끔하게 풀이해주신것 같아요~!! 고생하셨습니다 :)
PR Summary
문자열 지옥에 빠진 호석
https://www.acmicpc.net/problem/20166
풀이시간
12:42 ~ (문제 풀이 실패)
문제 조건
3 <= N,M <= 10
1 <= K <= 1,000
1 <= 신이 좋아하는 문자열 <= 5
시간 복잡도 :
O(N * M * 8^5 + K)
O(3,277,800)
접근법
무슨 알고리즘으로 풀이 할 수 있을까? -> BFS 탐색