회원가입
로그인
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
글쓰기
질문 도움말
자주묻는 질문
런타임에러
3190번 - 뱀
sktks11
3년 전
0
34퍼센트 쯤에서 오류가 발생합니다. 어디가 문제일까요?
n=int(input()) k=int(input()) graph=[[0]*n for i in range(n)] graph[0][0]=1 # 0 -> 우 1-> 좌 2->상 3->하 head=0 x=0 y=0 len=0 tail=[] count=0 for i in range(k): a,b = map(int,input().split()) graph[a-1][b-1]=2 l=int(input()) turn=[] for i in range(l): a,b=input().split() a = int(a) b = str(b) turn.append((a,b)) def move(): global graph , x,y,len,head,count,tail if head ==3: if x+1==n: count+=1 return count if graph[x+1][y] == 0 : if len>0: graph[tail[0][0]][tail[0][1]]=0 tail.append([x, y]) del tail[0] x += 1 graph[x][y] = 1 else: graph[x][y] = 0 x += 1 graph[x][y] = 1 elif graph[x+1][y]==1: count+=1 return count elif graph[x+1][y] ==2: tail.append([x,y]) len+=1 x += 1 graph[x][y] = 1 if head ==2: if x-1==-1: count+=1 return count if graph[x-1][y] == 0 : if len>0: graph[tail[0][0]][tail[0][1]]=0 tail.append([x, y]) del tail[0] x -= 1 graph[x][y] = 1 else: graph[x][y] = 0 x -= 1 graph[x][y] = 1 elif graph[x-1][y]==1: count += 1 return count elif graph[x-1][y] ==2: tail.append([x,y]) len+=1 x -= 1 graph[x][y] = 1 if head ==1: if y-1==-1: count += 1 return count if graph[x][y-1] == 0 : if len>0: graph[tail[0][0]][tail[0][1]] = 0 tail.append([x, y]) del tail[0] y -= 1 graph[x][y] = 1 else: graph[x][y] = 0 y -= 1 graph[x][y] = 1 elif graph[x][y-1]==1: count += 1 return count elif graph[x][y-1] ==2: tail.append([x,y]) len+=1 y -= 1 graph[x][y] = 1 if head ==0: if y+1==-1: count += 1 return count if graph[x][y+1] == 0 : if len>0: graph[tail[0][0]][tail[0][1]] = 0 tail.append([x, y]) del tail[0] y += 1 graph[x][y] = 1 else: graph[x][y] = 0 y += 1 graph[x][y] = 1 elif graph[x][y+1]==1: count += 1 return count elif graph[x][y+1] ==2: tail.append([x,y]) len+=1 y += 1 graph[x][y] = 1 count+=1 return -1 cnt=0 while 1: cnt += 1 check = move() for i in range(l): if cnt==turn[i][0]: if turn[i][1]=='D': if head ==0: head=3 elif head==1: head=2 elif head ==2: head=0 elif head ==3: head=1 if turn[i][1]=='L': if head ==0: head=2 elif head==1: head=3 elif head ==2: head=1 elif head ==3: head=0 if check==-1: pass else: print(check) break
댓글을 작성하려면
로그인
해야 합니다.
sktks11 3년 전
34퍼센트 쯤에서 오류가 발생합니다. 어디가 문제일까요?