회원가입
로그인
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
글쓰기
질문 도움말
자주묻는 질문
2178 미로탐색 런타임에러 봐주세요...
2178번 - 미로 탐색
misoning
7년 전
0
어디서 오래걸리는 건지 잘 못찾겠습니다...ㅠㅠ
package practice; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.LinkedList; import java.util.Queue; import java.util.StringTokenizer; public class Main { static int[] dr = { 1, -1, 0, 0 }; static int[] dc = { 0, 0, 1, -1 }; static int N; static int M; static class Point { int x; int y; public Point(int x, int y) { this.x = x; this.y = y; } } public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); Queue<Point> queue = new LinkedList<Point>(); StringTokenizer st = new StringTokenizer(br.readLine()); N = Integer.parseInt(st.nextToken()); M = Integer.parseInt(st.nextToken()); int[][] map = new int[N][M]; boolean[][] visited = new boolean[N][M]; for (int i = 0; i < N; i++) { String str = br.readLine(); for (int j = 0; j < M; j++) { map[i][j] = str.charAt(j) - '0'; } } queue.add(new Point(0, 0)); // 시작위치 visited[0][0] = true; // 방문처리 while (!queue.isEmpty()) { int r = queue.peek().x; int c = queue.peek().y; queue.poll(); if(r == N-1 && c == M-1) { break; } // 상하좌우 체크 후 이동 for (int i = 0; i < 4; i++) { int nextR = r + dr[i]; int nextC = c + dc[i]; if (!isIn(nextR, nextC)) { continue; } if (map[nextR][nextC] == 1 && !visited[nextR][nextC]) { map[nextR][nextC] = map[r][c] + 1; queue.add(new Point(nextR, nextC)); visited[nextR][nextC] = true; } } } // end of while System.out.println(map[N-1][M-1]); } // end of main static boolean isIn(int r, int c) { return (r >= 0 && r < N) && (c >= 0 && c < M); } }
djm03178
7년 전
1
package를 지워야 합니다.
misoning
7년 전
0
앗..민망하네요 감사합니다!!
댓글을 작성하려면
로그인
해야 합니다.
misoning 7년 전
어디서 오래걸리는 건지 잘 못찾겠습니다...ㅠㅠ