회원가입
로그인
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
글쓰기
질문 도움말
자주묻는 질문
런타임에러 좀 도와주세요.
3055번 - 탈출
taeminkim23
4년 전
0
Eclipse에서 돌릴 때는 답도 잘 나오는데
백준만 오면 런타임에러가 떠요..
왜 그럴까요.
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.LinkedList; import java.util.NoSuchElementException; import java.util.Queue; import java.util.StringTokenizer; public class Main { static class Location { int r; int c; public Location(int r, int c) { super(); this.r = r; this.c = c; } } static char map[][]; static Location sLoc; static Location wLoc; static int dirD[][] = { { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 } }; static boolean visit[][]; private static int R; private static int C; static int count = 0; static boolean flag = false; public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); R = Integer.parseInt(st.nextToken()); C = Integer.parseInt(st.nextToken()); map = new char[R][C]; visit = new boolean[R][C]; for (int i = 0; i < R; i++) { String str = br.readLine(); for (int j = 0; j < C; j++) { int val = str.charAt(j); map[i][j] = str.charAt(j); if (val == 'S') sLoc = new Location(i, j); else if (val == '*') wLoc = new Location(i, j); } } bfs(); if(flag) System.out.println("KAKTUS"); else System.out.println(count); } private static void bfs() { Queue<Location> squeue = new LinkedList<>(); Queue<Location> wqueue = new LinkedList<>(); squeue.add(sLoc); wqueue.add(wLoc); visit[sLoc.r][sLoc.c] = true; while (!squeue.isEmpty() || !wqueue.isEmpty()) { int wsize = wqueue.size(); int ssize = squeue.size(); // System.out.println("??"+count); count++; for (int i = 0; i < ssize; i++) { Location tmp = squeue.poll(); if (map[tmp.r][tmp.c] == '*') continue; for (int j = 0; j < dirD.length; j++) { int tmpR = tmp.r + dirD[j][0]; int tmpC = tmp.c + dirD[j][1]; if (tmpR < 0 || tmpR >= R || tmpC < 0 || tmpC >= C) continue; if (map[tmpR][tmpC] == 'X' || map[tmpR][tmpC] == '*') continue; if (map[tmpR][tmpC] == 'D') { return; } if(visit[tmpR][tmpC] == false){ visit[tmpR][tmpC] = true; squeue.add(new Location(tmpR, tmpC)); } } } for (int i = 0; i < wsize; i++) { Location tmp = wqueue.poll(); for (int j = 0; j < dirD.length; j++) { int tmpR = tmp.r + dirD[j][0]; int tmpC = tmp.c + dirD[j][1]; if (tmpR < 0 || tmpR >= R || tmpC < 0 || tmpC >= C) continue; if (map[tmpR][tmpC] == 'D' || map[tmpR][tmpC] == 'X' || map[tmpR][tmpC] == '*') continue; wqueue.add(new Location(tmpR, tmpC)); map[tmpR][tmpC] = '*'; } } } flag = true; } }
댓글을 작성하려면
로그인
해야 합니다.
taeminkim23 4년 전
Eclipse에서 돌릴 때는 답도 잘 나오는데
백준만 오면 런타임에러가 떠요..
왜 그럴까요.