회원가입
로그인
Toggle navigation
문제
문제
전체 문제
문제 출처
단계별로 풀어보기
알고리즘 분류
추가된 문제
문제 순위
문제
푼 사람이 한 명인 문제
아무도 못 푼 문제
최근 제출된 문제
최근 풀린 문제
랜덤
출처
ICPC
Olympiad
한국정보올림피아드
한국정보올림피아드시․도지역본선
전국 대학생 프로그래밍 대회 동아리 연합
대학교 대회
카카오 코드 페스티벌
Coder's High
ICPC
Regionals
World Finals
Korea Regional
Africa and the Middle East Regionals
Europe Regionals
Latin America Regionals
North America Regionals
South Pacific Regionals
문제집
대회
채점 현황
게시판
그룹
더 보기
재채점 기록
블로그
도움말
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
왜 틀린지 모르겠습니다 ㅠ
2573번 - 빙산
siosio0915
1년 전
0
왜 틀린지 모르겠습니다 ㅠ
# ************************************************************************** # # # # ::: ::: ::: # # Problem Number: 2573 :+: :+: :+: # # +:+ +:+ +:+ # # By: siosio0915 <boj.kr/u/siosio0915> +#+ +#+ +#+ # # +#+ +#+ +#+ # # https://boj.kr/2573 #+# #+# #+# # # Solved: 2024/12/19 13:03:17 by siosio0915 ### ### ##.kr # # # # ************************************************************************** # from collections import deque def is_out(): check_visited = [[False] * cols for _ in range(rows)] check_queue = deque() result = 0 for y in range(rows): for x in range(cols): if table[y][x] == 0 or check_visited[y][x]: continue check_queue.append((y, x)) check_visited[y][x] = True while check_queue: ny, nx = check_queue.popleft() for dy, dx in directions: ty, tx = dy + ny, dx + nx if ( ty >= rows or ty < 0 or tx >= cols or tx < 0 or check_visited[ty][tx] or table[ty][tx] == 0 ): continue check_visited[ty][tx] = True check_queue.append((ty, tx)) result += 1 return result >= 2 def bfs(visited): global queue next_queue = deque() while queue: ny, nx = queue.popleft() water_count = 0 for dy, dx in directions: ty, tx = ny + dy, nx + dx if not (0 <= ty < rows and 0 <= tx < cols) or visited[ty][tx]: continue if table[ty][tx] == 0: water_count += 1 elif not visited[ty][tx]: visited[ty][tx] = True next_queue.append((ty, tx)) table[ny][nx] = max(0, table[ny][nx] - water_count) queue = next_queue rows, cols = map(int, input().split()) table = [] queue = deque() directions = [[1, 0], [0, 1], [-1, 0], [0, -1]] for y in range(rows): row = list(map(int, input().split())) table.append(row) for x in range(cols): if table[y][x] != 0: queue.append((y, x)) if not queue: print(0) exit(0) if is_out(): print(0) exit(0) count = 0 while queue: count += 1 visited = [[False] * cols for _ in range(rows)] bfs(visited) if is_out(): print(count) exit(0) print(0) 제 답도 틀렸지만 뭐가 틀린지 모르겠습니다. ㅠㅠ
댓글을 작성하려면
로그인
해야 합니다.
siosio0915 1년 전
왜 틀린지 모르겠습니다 ㅠ