회원가입
로그인
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
문제집
대회
1
채점 현황
랭킹
게시판
그룹
더 보기
재채점 기록
블로그
강의
실험실
도움말
BOJ Stack
BOJ Book
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
테케는 전부 통과했는데 제출하자마자 틀렸다고 뜨네요
23289번 - 온풍기 안녕!
crucialzint
2년 전
0
흠...이럴 때 너무 난감하네요 ㅠㅠ
#백준 23289번 온풍기 안녕! from collections import deque from copy import deepcopy R,C,K=map(int,input().split()) fan=[] graph=[] search=[] for i in range(R): data=list(map(int,input().split())) for j in range(C): if 0<data[j]<5: fan.append([[i,j],data[j]]) data[j]=0 elif data[j]==5: search.append([i,j]) data[j]=0 graph.append(data) W=int(input()) wall=[[-1]*C for _ in range(R)] dx=[1,-1,0,0] dy=[0,0,1,-1] for _ in range(W): a,b,d=map(int,input().split()) a-=1 b-=1 wall[a][b]=d choco=0 while choco<=100: #1 온풍기에서 바람 나오기 for ma in fan: m_x=ma[0][0] m_y=ma[0][1] m_d=ma[1] #오른쪽 방향 if m_d==1: if m_y+1>=C: continue visited = [[False] * C for _ in range(R)] queue = deque() queue.append([m_x, m_y + 1, 5]) visited[m_x][m_y + 1] = True while queue: x, y, cnt = queue.popleft() if cnt <= 0: continue if x < 0 or x >= R or y < 0 or y >= C: continue graph[x][y] += cnt # 가운데 벽 if y + 1 <R: if not wall[x][y] == 1 and not visited[x][y + 1]: visited[x][y + 1] = True queue.append([x, y +1, cnt - 1]) # 위쪽 if x - 1 >= 0 and y+1<R: if not wall[x][y] == 0 and not wall[x - 1][y] == 1 and not visited[x - 1][y + 1]: visited[x - 1][y + 1] = True queue.append([x - 1, y + 1, cnt - 1]) # 아랫쪽 if x + 1 < R and y +1 <R: if not wall[x + 1][y] == 0 and not wall[x + 1][y] == 1 and not visited[x + 1][y + 1]: visited[x + 1][y + 1] = True queue.append([x + 1, y + 1, cnt - 1]) #왼쪽 방향 elif m_d==2: if m_y-1<0: continue visited=[[False]*C for _ in range(R)] queue=deque() queue.append([m_x,m_y-1,5]) visited[m_x][m_y-1]=True while queue: x,y,cnt=queue.popleft() if cnt<=0: continue if x<0 or x>=R or y<0 or y>=C: continue graph[x][y]+=cnt #가운데 벽 if y-1>=0: if not wall[x][y-1]==1 and not visited[x][y-1]: visited[x][y-1]=True queue.append([x,y-1,cnt-1]) #위쪽 if x-1>=0 and y-1>=0: if not wall[x][y]==0 and not wall[x-1][y-1]==1 and not visited[x-1][y-1]: visited[x-1][y-1]=True queue.append([x-1,y-1,cnt-1]) #아랫쪽 if x+1<R and y-1>=0: if not wall[x+1][y-1]==0 and not wall[x+1][y-1]==1 and not visited[x+1][y-1]: visited[x+1][y-1]=True queue.append([x+1,y-1,cnt-1]) #위쪽방향 elif m_d==3: if m_x-1<0: continue visited=[[False]*C for _ in range(R)] queue=deque() queue.append([m_x-1,m_y,5]) visited[m_x-1][m_y]=True while queue: x,y,cnt=queue.popleft() if cnt<=0: continue if x<0 or x>=R or y<0 or y>=C: continue graph[x][y]+=cnt #가운데 벽 if x-1>=0: if not wall[x][y]==0 and not visited[x-1][y]: visited[x-1][y]=True queue.append([x-1,y,cnt-1]) #왼쪽 if x-1>=0 and y-1>=0: if not wall[x][y-1]==0 and not wall[x][y-1]==1 and not visited[x-1][y-1]: visited[x-1][y-1]=True queue.append([x-1,y-1,cnt-1]) #오른쪽 if x-1>=0 and y+1<C: if not wall[x][y+1]==0 and not wall[x][y]==1 and not visited[x-1][y+1]: visited[x-1][y+1]=True queue.append([x-1,y+1,cnt-1]) #아랫방향 elif m_d==4: if m_x+1 >=R: continue visited = [[False] * C for _ in range(R)] queue = deque() queue.append([m_x +1, m_y, 5]) visited[m_x+ 1][m_y] = True while queue: x, y, cnt = queue.popleft() if cnt <= 0: continue if x < 0 or x >= R or y < 0 or y >= C: continue graph[x][y] += cnt # 가운데 벽 if x + 1 <R: if not wall[x+1][y] == 0 and not visited[x+1][y]: visited[x + 1][y] = True queue.append([x + 1, y, cnt - 1]) # 왼쪽 if x +1<R and y - 1 >= 0: if not wall[x+1][y - 1] == 0 and not wall[x][y - 1] == 1 and not visited[x + 1][y - 1]: visited[x + 1][y - 1] = True queue.append([x + 1, y - 1, cnt - 1]) # 오른쪽 if x + 1<R and y + 1 < C: if not wall[x+1][y + 1] == 0 and not wall[x][y] == 1 and not visited[x + 1][y + 1]: visited[x + 1][y + 1] = True queue.append([x + 1, y + 1, cnt - 1]) #2 온도조절 temp=deepcopy(graph) for x in range(R): for y in range(C): #상하좌우 다 더해주기 #상 if x-1>=0: if not wall[x][y]==0: diff=abs(graph[x][y]-graph[x-1][y]) diff//=4 if graph[x][y]>graph[x-1][y]: temp[x][y]-=diff else: temp[x][y]+=diff #하 if x+1<R: if not wall[x+1][y]==0: diff = abs(graph[x][y] - graph[x + 1][y]) diff //= 4 if graph[x][y] > graph[x + 1][y]: temp[x][y] -= diff else: temp[x][y] += diff #좌 if y-1>=0: if not wall[x][y-1]==1: diff = abs(graph[x][y] - graph[x][y-1]) diff //= 4 if graph[x][y] > graph[x][y-1]: temp[x][y] -= diff else: temp[x][y] += diff #우 if y+1<C: if not wall[x][y]==1: diff = abs(graph[x][y] - graph[x][y+1]) diff //= 4 if graph[x][y] > graph[x][y+1]: temp[x][y] -= diff else: temp[x][y] += diff graph=deepcopy(temp) #2-1 맨 끝 감소 for x in range(R): if x==0 or x==R-1: for y in range(C): if graph[x][y]>0: graph[x][y]-=1 else: if graph[x][0]>0: graph[x][0]-=1 if graph[x][C-1]>0: graph[x][C-1]-=1 #3 초콜릿 먹기 choco+=1 #4 조사하는 모든 칸의 온도가 K이상인지 검사 #K이상이면 중단. no=0 for find in search: if graph[find[0]][find[1]]<K: no=1 break if no==0: break print(choco)
댓글을 작성하려면
로그인
해야 합니다.
crucialzint 2년 전
흠...이럴 때 너무 난감하네요 ㅠㅠ