회원가입
로그인
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
글쓰기
질문 도움말
자주묻는 질문
런타임 에러 왜 뜰까용 ㅜ.ㅜ
2178번 - 미로 탐색
dongpee
7년 전
0
채점하기도전에 런타임이 떠버리는데 조금 봐주실수 있을까용 ㅜ.ㅜ
package BFS; import java.util.*; public class Baek2178 { public static void main(String[] args) { Scanner in = new Scanner(System.in); //목적지 입력받기 int n = in.nextInt(); int m = in.nextInt(); int[][] miro = new int[n][m]; boolean[][] check = new boolean[n][m]; int[][] dist = new int[n][m]; //미로 입력받기 for(int i=0; i<n; i++){ String temp = in.next(); for(int j=0; j<m; j++){ if(temp.charAt(j) == '1') miro[i][j] = 1; } } Queue q = new Queue(100); q.push(new Point(0,0)); dist[0][0] = 1; check[0][0] = true; while(!q.isEmpty()){ Point now = q.pop(); if(now.x-1 >= 0 && miro[now.x-1][now.y] == 1 && check[now.x-1][now.y] == false){ dist[now.x-1][now.y] = dist[now.x][now.y] + 1; check[now.x-1][now.y] = true; q.push(new Point(now.x-1, now.y)); } if(now.x+1 < n && miro[now.x+1][now.y] == 1 && check[now.x+1][now.y] == false){ dist[now.x+1][now.y] = dist[now.x][now.y] + 1; check[now.x+1][now.y] = true; q.push(new Point(now.x+1, now.y)); } if(now.y-1 >= 0 && miro[now.x][now.y-1] == 1 && check[now.x][now.y-1] == false){ dist[now.x][now.y-1] = dist[now.x][now.y] + 1; check[now.x][now.y-1] = true; q.push(new Point(now.x, now.y-1)); } if(now.y+1 < m && miro[now.x][now.y+1] == 1 && check[now.x][now.y+1] == false){ dist[now.x][now.y+1] = dist[now.x][now.y] + 1; check[now.x][now.y+1] = true; q.push(new Point(now.x, now.y+1)); } } System.out.println(dist[n-1][m-1]); } static class Point{ private int x, y; Point(int x, int y){ this.x = x; this.y = y; } } static class Queue{ private int front; private int rear; private Point[] queue; public Queue(int size){ front = rear = -1; queue = new Point[size]; } public void push(Point num){ queue[++rear] = num; } public Point pop(){ return queue[++front]; } public boolean isEmpty(){ return front == rear; } } }
댓글을 작성하려면
로그인
해야 합니다.
dongpee 7년 전
채점하기도전에 런타임이 떠버리는데 조금 봐주실수 있을까용 ㅜ.ㅜ