회원가입
로그인
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
글쓰기
질문 도움말
자주묻는 질문
15% 틀렸습니다.
2573번 - 빙산
dkdlel6887
3년 전
0
아래 풀이는 맞고 위에 풀이는 틀렸습니다가 뜨는데 뭐가 문제일까요 논리는 똑같은데 ..
# from collections import deque # N, M = map(int, input().split()) # maps = [list(map(int, input().split())) for _ in range(N)] # directions = [(1, 0), (-1, 0), (0, 1), (0, -1)] # answer = 0 # def melt_count(answer): # while True: # visited = [[0] * M for _ in range(N)] # ice = [[0] * M for _ in range(N)] # cnt = 0 # q = deque([]) # iceleft = 0 # for y in range(1, N - 1): # for x in range(1, M - 1): # if maps[y][x] != 0: # iceleft += 1 # # check icebulgs # if ice[y][x] == 0: # cnt += 1 # if cnt == 2: # return answer # q.append((y, x)) # ice[y][x] = 1 # while q: # cy, cx = q.popleft() # for dy, dx in directions: # ny = cy + dy # nx = cx + dx # if 0 <= ny < N and 0 <= nx < M and maps[ny][nx] != 0 and ice[ny][nx] == 0: # ice[ny][nx] = 1 # q.append((ny, nx)) # # melting # water = 0 # for dy, dx in directions: # ny = y + dy # nx = x + dx # if 0 <= ny < N and 0 <= nx < M and maps[ny][nx] == 0: # water += 1 # visited[y][x] = min(maps[y][x], water) # if iceleft == 0: # 녹아서 얼음이 다사라진 경우 # return 0 # for i in range(1, N - 1): # for j in range(1, M - 1): # if visited[i][j] != 0: # maps[i][j] -= visited[i][j] # answer += 1 # answer = melt_count(answer) # print(answer) ###################################################################### from collections import deque N, M = map(int, input().split()) maps = [list(map(int, input().split())) for _ in range(N)] directions = [(1, 0), (-1, 0), (0, 1), (0, -1)] def melt(): # 빙산 녹는 함수 melting = [] for y in range(1, N - 1): for x in range(1, M - 1): if maps[y][x] != 0: water = 0 for dy, dx in directions: ny = y + dy nx = x + dx if 0 <= ny < N and 0 <= nx < M and maps[ny][nx] == 0: water += 1 melting.append((y,x,min(maps[y][x], water))) for i,j,k in melting: maps[i][j] -= k def countice(): # 빙산 개수 확인 함수 ice = [[0] * M for _ in range(N)] cnt = 0 q = deque([]) for y in range(1, N - 1): for x in range(1, M - 1): if maps[y][x] != 0 and ice[y][x] == 0: cnt += 1 if cnt == 2: return cnt # two island q.append((y, x)) ice[y][x] = 1 while q: y, x = q.popleft() for dy, dx in directions: ny = y + dy nx = x + dx if 0 <= ny < N and 0 <= nx < M and maps[ny][nx] != 0 and ice[ny][nx] == 0: ice[ny][nx] = 1 q.append((ny, nx)) return cnt answer = 0 while True: icebulgs = countice() if icebulgs == 1: melt() answer += 1 elif icebulgs == 0: answer = 0 break else: break print(answer)
댓글을 작성하려면
로그인
해야 합니다.
dkdlel6887 3년 전
아래 풀이는 맞고 위에 풀이는 틀렸습니다가 뜨는데 뭐가 문제일까요 논리는 똑같은데 ..