회원가입
로그인
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
글쓰기
질문 도움말
자주묻는 질문
2174번 런타임오류가 발생하는데, 리뷰 부탁드려요ㅜ
2174번 - 로봇 시뮬레이션
wnhoyt77
2년 전
0
계속 런타임오류(indexerror)라고 발생하는데 이유를 모르겠어서 질문 올립니다
도와주시면 감사하겠습니다ㅜㅠ
E, S, W, N = 1,2,3,4 dirX = [0, 1, 0, -1, 0] dirY = [0, 0, 1, 0, -1] A, B = map(int, input().split()) N, M = map(int, input().split()) land = [[-1]*A for _ in range(B)] robot = [[]] answer = 'OK' for i in range(N) : x, y, dir = input().split() x, y = int(x), int(y) if dir == 'W' : dir = W elif dir == 'S' : dir = S elif dir == 'E' : dir = E elif dir == 'N' : dir = N robot.append([x-1, B-y, dir]) land[B-y][x-1] = i+1 for i in range(M) : r_idx, cmd, num = input().split() r_idx, num = int(r_idx), int(num) if cmd == 'F' : # 직진 crash = False nextX, nextY = robot[r_idx][0], robot[r_idx][1] for _ in range(num) : nextX += dirX[robot[r_idx][2]] nextY += dirY[robot[r_idx][2]] if nextX < 0 or nextX >= A or nextY < 0 or nextY >= B : answer = 'Robot {} crashes into the wall'.format(r_idx) crash = True break elif land[nextY][nextX] != -1 : answer = 'Robot {0} crashes into robot {1}'.format(r_idx, land[nextY][nextX]) crash = True break if crash : break x, y = robot[r_idx][0], robot[r_idx][1] land[nextY][nextX] = r_idx land[y][x] = -1 robot[r_idx][0], robot[r_idx][1] = nextX, nextY else : cnt = num%4 if cnt == 0 : continue if cmd == 'R' : for _ in range(cnt) : if robot[r_idx][2] == 4 : robot[r_idx][2] = 1 else : robot[r_idx][2] += 1 elif cmd == 'L' : for _ in range(cnt) : if robot[r_idx][2] == 1 : robot[r_idx][2] = 4 else : robot[r_idx][2] -= 1 print(answer)
댓글을 작성하려면
로그인
해야 합니다.
wnhoyt77 2년 전
계속 런타임오류(indexerror)라고 발생하는데 이유를 모르겠어서 질문 올립니다
도와주시면 감사하겠습니다ㅜㅠ