회원가입
로그인
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
글쓰기
질문 도움말
자주묻는 질문
테케는 다 통과하는데 어디가 틀린건지 도저히 모르겠어요 ㅠㅠ
14503번 - 로봇 청소기
ckdgus1433
3년 전
0
제목 그대로입니다 ㅠ 테케는 맞는데 어떤게 오류가 있는지 도저히 잘 모르겠어서 이렇게 질문 드리게 되었습니다!
n, m = map(int, input().split()) from collections import deque dir = deque([0, 1, 2, 3]) bot_y, bot_x, bot_direction = map(int, input().split()) dir.rotate(-bot_direction) bot_y, bot_x = bot_y-1, bot_x-1 board = [list(map(int, input().split())) for _ in range(n)] visit = [[0]*m for _ in range(n)] for y in range(n): for x in range(m): if x == 0 or x == m-1 or y == 0 or y == n-1: visit[y][x] = 1 def sh(y, x, direction): # search if direction == 0: # 북 if visit[y - 1][x] == 0 and board[y - 1][x] == 0: return True elif direction == 1: # 동 if visit[y][x + 1] == 0 and board[y][x + 1] == 0: return True elif direction == 2: # 남 if visit[y + 1][x] == 0 and board[y + 1][x] == 0: return True elif direction == 3: # 서 if visit[y][x - 1] == 0 and board[y][x - 1] == 0: return True return False def move(y, x, direction): if direction == 0: # 북 return y-1, x elif direction == 1: # 동 return y, x+1 elif direction == 2: # 남 return y+1, x elif direction == 3: # 서 return y, x-1 def move_back(y, x, direction): if direction == 0: # 북 return y+1, x elif direction == 1: # 동 return y, x-1 elif direction == 2: # 남 return y-1, x elif direction == 3: # 서 return y, x+1 # 네 방향 모두 청소가 이미 되어 있거나 벽인 경우 True 리턴 def check_4d(bot_y, bot_x): if (visit[bot_y-1][bot_x] == 1 or board[bot_y-1][bot_x] == 1) and \ (visit[bot_y][bot_x+1] == 1 or board[bot_y][bot_x+1] == 1) and \ (visit[bot_y+1][bot_x] == 1 or board[bot_y+1][bot_x] == 1) and \ (visit[bot_y][bot_x-1] == 1 or board[bot_y][bot_x-1] == 1): return True return False def solve(): global bot_y, bot_x cnt = 1 while True: if visit[bot_y][bot_x] == 0: # 현재 위치를 청소한다. visit[bot_y][bot_x] = 1 cnt += 1 if check_4d(bot_y, bot_x) == True: # 네 방향 모두 청소가 이미 되어 있거나 벽인 경우, bot_y, bot_x = move_back(bot_y, bot_x, dir[0]) # 바라보는 방향을 유지한 채로 한 칸 후진 if board[bot_y][bot_x] == 1: # 뒤쪽 방향이 벽이라 후진도 할 수 없는 경우, 작동 멈춤 # print('작동 중지') return cnt else: if visit[bot_y][bot_x] == 0: visit[bot_y][bot_x] = 1 cnt += 1 else: dir.rotate(1) # 왼쪽 방향부터 차례대로 탐색 진행 if sh(bot_y, bot_x, dir[0]) == True: # 왼쪽 방향에 아직 청소하지 않은 공간이 존재한다면 bot_y, bot_x = move(bot_y, bot_x, dir[0]) # 1칸 전진 if visit[bot_y][bot_x] == 0: visit[bot_y][bot_x] = 1 cnt += 1 elif sh(bot_y, bot_x, dir[0]) == False: # 왼쪽 방향에 청소할 공간이 없다면 continue cnt = solve() print(cnt)
댓글을 작성하려면
로그인
해야 합니다.
ckdgus1433 3년 전
제목 그대로입니다 ㅠ 테케는 맞는데 어떤게 오류가 있는지 도저히 잘 모르겠어서 이렇게 질문 드리게 되었습니다!