회원가입
로그인
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
글쓰기
질문 도움말
자주묻는 질문
오답 처리가 됩니다.
16928번 - 뱀과 사다리 게임
kyontoki
2년 전
0
테스트 케이스도 모두 넣어 봤는데 오답 처리가 되네요,..
from collections import deque N, M = map(int, input().split()) board = [0] * 101 # board 판, index별 값은 이동 횟수(굴린 횟수) visited = [False] * 101 # 방문 한 곳인지 check ladder = dict() snake = dict() for i in range(N): a1, b1 = map(int, input().split()) ladder[a1] = b1 for i in range(M): a2, b2 = map(int, input().split()) snake[a2] = b2 queue = deque([1]) # queue 생성 while queue: a = queue.popleft() if a == 100: print(board[a]) break for d in range(1, 7): # 주사위 던지기 next_pos = a + d if next_pos <= 100 and not visited[next_pos]: # 맵 안넘어가고, 방문한 적이 없으면 visited[next_pos] = True if next_pos in ladder.keys(): # 사다리 칸에 있으면, next_pos = ladder[next_pos] visited[next_pos] = True board[next_pos] = board[a] + 1 elif next_pos in snake.keys(): # 뱀 칸으로 오면 next_pos = snake[next_pos] visited[next_pos] = True board[next_pos] = board[a] + 1 else: # visited[next_pos] = True # 방문 처리(사다리도 아니고 뱀도 아닐때) board[next_pos] = board[a] + 1 # if next_pos == 100: # 목적지에 도착했다면 종료 # print(board[next_pos]) # exit() queue.append(next_pos)
댓글을 작성하려면
로그인
해야 합니다.
kyontoki 2년 전
테스트 케이스도 모두 넣어 봤는데 오답 처리가 되네요,..